請在下面找到x ++查詢的示例。但你必須記住,在標準AX領域PurchId和JournalId有不同的長度,你會得到以下錯誤:
There is a field mismatch in the union query. Field JournalId is not compatible with field PurchId.
Query query;
QueryBuildDataSource qbdsInventJournalTrans;
QueryBuildDataSource qbdsPurchLine;
QueryBuildRange qbrInventJournalTrans;
QueryBuildRange qbrPurchLine;
;
query = new Query();
query.queryType(QueryType::Union);
qbdsInventJournalTrans = query.addDataSource(tableNum(InventJournalTrans));
qbdsInventJournalTrans.unionType(UnionType::UnionAll); // Include duplicate records
qbdsInventJournalTrans.fields().dynamic(false);
qbdsInventJournalTrans.fields().clearFieldList();
qbdsInventJournalTrans.fields().addField(fieldNum(InventJournalTrans, AssetId));
qbdsInventJournalTrans.fields().addField(fieldNum(InventJournalTrans, ItemId));
//qbdsInventJournalTrans.fields().addField(fieldNum(InventJournalTrans, JournalId));
qbrInventJournalTrans = qbdsInventJournalTrans.addRange(fieldNum(InventJournalTrans, AssetId));
qbrInventJournalTrans.value(SysQuery::valueNotEmptyString());
qbdsPurchLine = query.addDataSource(tableNum(PurchLine));
qbdsPurchLine.unionType(UnionType::UnionAll); // Include duplicate records
qbdsPurchLine.fields().dynamic(false);
qbdsPurchLine.fields().clearFieldList();
qbdsPurchLine.fields().addField(fieldNum(PurchLine, AssetId));
qbdsPurchLine.fields().addField(fieldNum(PurchLine, ItemId));
//qbdsPurchLine.fields().addField(fieldNum(PurchLine, PurchId));
qbrPurchLine = qbdsPurchLine.addRange(fieldNum(PurchLine, AssetId));
qbrPurchLine.value(SysQuery::valueNotEmptyString());
,如果你需要創建AOT查詢請參考以下鏈接How to: Combine Data Sources
你看過[查看概述](https://msdn.microsoft.com/en-us/library/cc634339(v = ax.50).aspx)和[如何合併數據源](https ://msdn.microsoft.com/en-us/library/cc605991(v = ax.50)的.aspx)? –