当以下代码执行时:
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 将第二个 notExists 连接 (salesTable) 嵌套到第一个 notExists 连接 (custTable) 的 where 子句中。IE
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 连接到 inventTrans 表而不是 custTable,因此生成的 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)