2016-10-26 73 views
1
我有與AX2012類的麻煩

(默認AX2012類代碼,沒有做過修改就可以了) :更換EXISTS JOIN與JOIN

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; 
} 

我明白爲什麼,但我不知道如何解決這個問題。將exist join替換爲正常的join會造成問題嗎?

join代替exist join,解決了我的問題,但我不確定它會對數據有什麼不同?因爲它只是選擇1場?

回答

2

你可以嘗試切換順序的加入:

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(); 
+0

謝謝,這解決了我的問題。 –

1

用連接替換存在的連接不會解決您的問題。 Exist是一種連接到表的基本上內連接而不返回任何字段的方式。

查詢應該從_custVendAccountStatementIntTmpProcessing和AccountingCurrencyAmount從generalJournalAccountEntry返回CustVendTransRefRecId,這正是insert所期望的。

我希望查詢實際上沒有返回任何東西。檢查它使用的標準並檢查數據。