2017-02-23 41 views
0

多條記錄我要更新多臺SalesQuotationLines匹配報價ID爲X更新在同一個表

salesQuotationLine = salesQuotationLine::find(quotationId,true); 

salesQuotationLine.selectForUpdate(true); 

if(salesQuotationLine) { 

ttsBegin; 

SalesQuotationLine.Field = newFieldValue; 
salesQuotationLine.update(); 

ttscommit; 

的問題是,這只是更新是在find方法中找到的第一個記錄。

我怎樣才能確保所有符合QuotationID的記錄都被更新?

回答

2

您可以使用此代碼:

while select forupdate salesQuotationLine 
where salesQuotationLine.quotationId == quotationId 
{ 
    salesQuotationLine..Field = newFieldValue; 
    ttsbegin; 
    salesQuotationLine.update(); 
    ttscommit; 
} 

又可以使用_update_recordset_

ttsbegin; 
update_recordset salesQuotationLine 
setting 
Field = newFieldValue 
where salesQuotationLine.quotationId == quotationId 
ttscommit; 

我希望砧木的問題。

0

Dynanics AX 2012提供了使用X ++ SQL語句來增強性能的方法。此選項是update_recordset,它允許您在單次到服務器的單行中更新多行:

update_recordset salesQuotationLine 
setting 
    Field = newFieldValue 
where salesQuotationLine.quotationId == quotationId;