2017-03-06 46 views
0

我想在dynamics ax 2009中創建視圖,此視圖必須返回兩個或多個具有相同字段名稱的表。Dynamics Axis 2009:使用UNION和具有相同字段名稱的表創建視圖

我準備了sql查詢(查詢如下),但我不知道如何將這些腳本移動到ax視圖中。

select invent.ASSETID, invent.ITEMID, invent.JOURNALID as 'ids' 
    from inventjournaltrans invent 
    where invent.ASSETID != '' 

UNION 

select purch.ASSETID, purch.ITEMID, purch.PURCHID as 'ids' 
    from purchline purch 
    where purch.ASSETID != '' 
+0

你看過[查看概述](https://msdn.microsoft.com/en-us/library/cc634339(v = ax.50).aspx)和[如何合併數據源](https ://msdn.microsoft.com/en-us/library/cc605991(v = ax.50)的.aspx)? –

回答

0

請在下面找到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

相關問題