用 JOIN 替换 EXISTS JOIN

Replacing EXISTS JOIN with JOIN

我在使用 AX2012 class 时遇到问题(默认 AX2012 class 和代码,未对其进行任何修改):CustVendTransDetails 在方法 calcCashDiscounts

以下查询给出错误 The select list for the INSERT statement contains fewer items than the insert list. The number of SELECT values must match the number of INSERT columns.:

if (TaxParameters::canApplyCashDiscOnInvoice_ES())
{
    insert_recordset tmpValue
        (CustVendTransRefRecId, AmountMST)
        select CustVendTransRefRecId
        from _custVendAccountStatementIntTmpProcessing

        exists join custVendTransLoc
        where
            custVendTransLoc.RecId == _custVendAccountStatementIntTmpProcessing.CustVendTransRefRecId

        exists join firstOnly subledgerVoucherGeneralJournalEntry
        where
            subledgerVoucherGeneralJournalEntry.Voucher == custVendTransLoc.Voucher &&
            subledgerVoucherGeneralJournalEntry.AccountingDate == custVendTransLoc.TransDate

        exists join generalJournalEntry
        where
            generalJournalEntry.RecId == subledgerVoucherGeneralJournalEntry.GeneralJournalEntry &&
            generalJournalEntry.Ledger == Ledger::current()

        join AccountingCurrencyAmount from generalJournalAccountEntry
        where
            generalJournalAccountEntry.GeneralJournalEntry == generalJournalEntry.RecId &&
            (generalJournalAccountEntry.PostingType == LedgerPostingType::CustCashDisc ||
            generalJournalAccountEntry.PostingType == LedgerPostingType::VendCashDisc);

    update_recordSet _custVendAccountStatementIntTmpProcessing setting
        UtilizedCashDisc = tmpValue.AmountMST,
        PossibleCashDisc = tmpValue.AmountMST
        join tmpValue
        where
            tmpValue.CustVendTransRefRecId == _custVendAccountStatementIntTmpProcessing.CustVendTransRefRecId;
}

我明白为什么,但我不知道如何解决这个问题。用普通的 join 替换 exist join 会有问题吗?

join 替换 exist join 确实解决了我的问题,但我不确定它会对数据产生什么影响?因为它只是选择 1 个字段?

用 join 替换 exist join 不会解决您的问题。 Exist 是一种加入本质上内部加入 table 的方法,无需 returning 任何字段。

查询应该 return 来自 _custVendAccountStatementIntTmpProcessing 的 CustVendTransRefRecId 和来自 generalJournalAccountEntry 的 AccountingCurrencyAmount,这正是插入所期望的。

我预计该查询实际上 return 没有任何内容。检查它使用的标准并检查数据。

您可以尝试切换连接顺序:

insert_recordset tmpValue (CustVendTransRefRecId, AmountMST)
    select CustVendTransRefRecId
    from _custVendAccountStatementIntTmpProcessing

    join AccountingCurrencyAmount from generalJournalAccountEntry // Moved up
    where generalJournalAccountEntry.PostingType == LedgerPostingType::CustCashDisc ||
          generalJournalAccountEntry.PostingType == LedgerPostingType::VendCashDisc

    exists join custVendTransLoc
    where
        custVendTransLoc.RecId == _custVendAccountStatementIntTmpProcessing.CustVendTransRefRecId

    exists join firstOnly subledgerVoucherGeneralJournalEntry
    where
        subledgerVoucherGeneralJournalEntry.Voucher == custVendTransLoc.Voucher &&
        subledgerVoucherGeneralJournalEntry.AccountingDate == custVendTransLoc.TransDate

    exists join generalJournalEntry
    where
        generalJournalEntry.RecId == subledgerVoucherGeneralJournalEntry.GeneralJournalEntry && &&
        generalJournalEntry.RecId == generalJournalAccountEntry.GeneralJournalEntry && // Moved from join
        generalJournalEntry.Ledger == Ledger::current();