次のコードが実行されると:
select sum(qty) from inventTrans
index hint TransTypeIdx
where inventTrans.ItemId == itemId
&& inventTrans.TransType == InventTransType::Sales
&& inventTrans.InventDimId == inventDimId
notExists join custTable
where custTable.AccountNum == inventTrans.CustVendAC
&& custTable.CustGroup == custGroupId
notExists join salesTable
where salesTable.SalesId == inventTrans.TransRefId
&& salesTable.Extraordinary == NoYes::Yes;
生成された SQL は、2 番目の notExists 結合 (salesTable) を最初の notExists 結合 (custTable) の where 句にネストします。すなわち
SELECT SUM(A.QTY)
FROM
INVENTTRANS A
WHERE
A.DATAAREAID = 'MyCompany'
AND A.ITEMID = 'MyItem'
AND A.TRANSTYPE = 0
AND A.INVENTDIMID = 'SomeValue'
AND NOT EXISTS (SELECT 'x'
FROM CUSTTABLE C
WHERE C.DATAAREAID ='MyCompany'
AND C.ACCOUNTNUM =A.CUSTVENDAC
AND C.CUSTGROUP ='SomeCustGroup'
AND NOT EXISTS (SELECT 'x'
FROM SALESTABLE B
WHERE
B.DATAAREAID ='MyCompany'
AND B.SALESID =A.TRANSREFID
AND B.EXTRAORDINARY =1))
X++ 選択クエリを記述して、notExists が custTable の代わりに salesTable を inventTrans テーブルに結合するように記述する方法はありますか? その場合、生成される SQL は次のようになりますか?
SELECT SUM(A.QTY)
FROM
INVENTTRANS A
WHERE A.DATAAREAID = 'MyCompany'
AND A.ITEMID = 'MyItem'
AND A.TRANSTYPE = 0
AND A.INVENTDIMID = 'SomeValue'
AND NOT EXISTS (SELECT 'x'
FROM CUSTTABLE C
WHERE C.DATAAREAID ='MyCompany'
AND C.ACCOUNTNUM =A.CUSTVENDAC
AND C.CUSTGROUP ='SomeCustGroup')
AND NOT EXISTS (SELECT 'x'
FROM SALESTABLE B
WHERE
B.DATAAREAID='MyCompany'
AND B.SALESID=A.TRANSREFID
AND B.EXTRAORDINARY=1)