안녕하세요..조복기입니다..
제가 예전에 답변했던 질문이군요..찾아보니까..
델파이헬프 및 델파이메뉴얼에 나와있는 내용입니다..
참고하시기 바랍니다.
질문하시기 전에 기존 데이타를 조회하는 습관을 가지시길 바랍니다..
좋은하루되세요..
--------------------------------------------------------------
안녕하세요..
제가 예전에 델파이메뉴얼에서 본게 기억이나서 헬프를 찾았더니
자세하게 예제까기 나와있네요..
참고로 다른DB안의 table조인은 앨리어스를 가지고
조인을 한답니다. 참고가 되셨는지..
--------------------------------------------------------------
헬프색인 : Heterogeneous joins
Joins two tables from different databases.
SELECT column_list
FROM ":database_reference:table_reference", ":database_reference:table_reference" [,":database_reference:table_reference"...]
WHERE predicate [AND predicate...]
Description
Use a heterogeneous join to join two tables that reside in different databases. The joined tables may be of different types (like dBASE to Paradox or Paradox to InterBase), but you can only join tables whose database types are accessible through the BDE (local, ODBC, or SQL Links). A hetergeneous join may be any of the joins supported by local SQL. The difference is in the syntax for the table reference: the database containing each table is specified in the table reference, surrounded by colons and the whole reference enclosed in quotation marks. The database specified as part of the table reference may be a drive and directory reference (for local tables) or a BDE alias.
SELECT *
FROM ":DBDEMOS:customer.db" C, ":BCDEMOS:orders.db" O
WHERE (C.custno = O.custno)
--------------------------------------------------------------
하윤철 께서 말씀하시기를...
> Oracle에 있는 테이블의 A 필드를 참조해서 MSSQL에서 조회를 해야 하거든요....
>
> Select AAA.*
> From AAA, BBB // 여기서 AAA : MSSQL BBB : Oracle
> Where AAA.B = BBB.B
> and BBB.A = '델파이'
>
> 보기는 간단하지요??
> 바로 되면 정말 좋겠고요... 안되면 ClientDB를 써서 한다리 건너서라도...
> 아이디어 좀 주세요...
>
코드를 그대로 올리니 한번 봐주십쇼.
SELECT
Substring(SlipMain.Before_Slip_No, 1, 2) + '-' +
Substring(SlipMain.Before_Slip_No, 3, 8) + '-' +
Substring(SlipMain.Before_Slip_No, 11, 3) + '-' +
Substring(SlipMain.Before_Slip_No, 14, 1) as BSN,
Substring(a.Account, 1, 4) + '-' +
Substring(a.Account, 5, 2) + '-' +
Substring(a.Account, 7, 2) + ' ' + a.Account_No_Kor as AccountC,
b.code_name as mi1,
c.code_name as mi2,
d.code_name as mi3,
e.code_name as mi4,
f.code_name as mi5,
SlipMain.Manage_Item_Input1 + ' ' + SlipMain.Manage_Item_Title1 as MIT1,
SlipMain.Manage_Item_Input2 + ' ' + SlipMain.Manage_Item_Title2 as MIT2,
SlipMain.Manage_Item_Input3 + ' ' + SlipMain.Manage_Item_Title3 as MIT3,
SlipMain.Manage_Item_Input4 + ' ' + SlipMain.Manage_Item_Title4 as MIT4,
SlipMain.Manage_Item_Input5 + ' ' + SlipMain.Manage_Item_Title5 as MIT5,
SlipMain.Debit_Amount,
SlipMain.Credit_Amount
FROM ":s_acctdb:magic.bzin0300" a, //MS-SQL
":s_acctdb:magic.bzin0501" b, //MS-SQL
":s_acctdb:magic.bzin0501" c, //MS-SQL
":s_acctdb:magic.bzin0501" d, //MS-SQL
":s_acctdb:magic.bzin0501" e, //MS-SQL
":s_acctdb:magic.bzin0501" f, //MS-SQL
":s_acctdb:magic.baga0401" SlipMain, //MS-SQL
(Select INVOICE1 From ":maximo:Invoice" //ORACLE
Where EnterBy = 'BYEONAJ'
and Convert(String, Inv.INVOICEDATE) between '19990701'
and '19990719') Inv
WHERE Inv.INVOICE1 = SlipMain.Before_Slip_No
AND a.account = SlipMain.Account
AND b.class = 'MC'
AND b.dtail =* a.manage_item1
AND c.class = 'MC'
AND c.dtail =* a.manage_item2
AND d.class = 'MC'
AND d.dtail =* a.manage_item3
AND e.class = 'MC'
AND e.dtail =* a.manage_item4
AND f.class = 'MC'
AND f.dtail =* a.manage_item5
Order By SlipMain.Before_Slip_No, SlipMain.Sequence
이상은 문법과 함수를 MS-SQL 측면에서 쓴겁니다. 이렇게 하면 :maximo:Invoice 객체를 찾을수 없다고 나옵니다.
위 쿼리를 Oracle 문법으로 바꿔 쓰면? Convert하고 Outer Join 문법이 달라지겠지요? 그래도 SQL Statement가 비정상 종결