4

当以下代码执行时:

   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)
4

2 回答 2

1

您可能不再等待答案,但在 Axe 2012 上我仍然遇到了同样的问题。

找到了另一种解决方案(除了使用 SQL 语句),不是性能最高的解决方案,但它有效:

  • 创建查询: select * from inventTrans noteexists join CustTable ....
  • 基于该查询创建视图
  • 对 salesTable 做同样的事情
  • 更改您的选择语句如下:

    选择 inventTrans

    ...

    存在加入 myCustView

    其中 myCustView.InventTransRecId == inventTrans.RecId

    存在加入 mySalesView

    在哪里 ...

希望这可以帮助,

于 2012-08-08T12:21:38.840 回答
1

简短的回答:不!

在您的示例中,您可以使用内部连接重新制定:

select sum(qty) from inventTrans
    index hint TransTypeIdx
    where inventTrans.ItemId        == itemId
       && inventTrans.TransType     == InventTransType::Sales
       && inventTrans.InventDimId   == inventDimId
    join salesTable
    where salesTable.SalesId        == inventTrans.TransRefId
       && salesTable.Extraordinary  == NoYes::No;
    notExists join custTable
    where custTable.AccountNum      == inventTrans.CustVendAC
       && custTable.CustGroup       == custGroupId

如果您在开票时不删除销售订单,它应该可以工作。

于 2009-04-17T06:57:33.657 回答