Axapta 如何在中使用创建查询?

Axapta 如何在中使用创建查询?,axapta,x++,dynamics-ax-2012-r3,Axapta,X++,Dynamics Ax 2012 R3,我需要收集数据并使用X++将其添加到AX 2012 R3中的临时表中 这是对SQL的查询 select store, receiptid, itemid, str(qty,16,0) as Qty, str(price,16,0) as Price, str(DISCAMOUNT,16,0) DiscAmount, str(taxamount,16,0) SalesTaxAmount ,convert(date, transdate) transdate, DATAAREAID from R

我需要收集数据并使用X++将其添加到AX 2012 R3中的临时表中

这是对SQL的查询

select store, receiptid, itemid, str(qty,16,0) as Qty, str(price,16,0) as   Price, str(DISCAMOUNT,16,0) DiscAmount, str(taxamount,16,0) SalesTaxAmount ,convert(date, transdate) transdate, DATAAREAID from RETAILTRANSACTIONSALESTRANS
where DATAAREAID in ('5740','5760') and transdate >='2016-03-21' and transdate <='2016-03-27' and store in ('JTJDRN1','JNUSADP','JOFFICE')
and INVENTSTATUSSALES='2' and itemid in ('10010038') and receiptid in (select receiptid from RETAILTRANSACTIONPAYMENTTRANS where transdate >='2016-03-21' and transdate <='2016-03-27')
order by transdate
有限制,长周期显示错误

有人能让我的代码更高效、更可靠吗 有没有办法在x++中创建与SQL上的“in”功能相同的查询?您有两个选项:

  • 同一字段可以使用多个查询范围;它将自动计为

    for (i = conLen(items); i > 0; i--)
        qbdsRetailTransactionSalesTrans.addRange(fieldNum(RetailTransactionSalesTrans, itemId)).value(queryValue(conPeek(items,i)));
    
    如果集装箱是空的,您可能需要特殊处理

  • 通常最好使用(exists)连接

    ds = qbdsRetailTransactionSalesTrans.addDatasource(tableNum(RetailTransactionPaymentTrans));
    ds.joinMode(JoinMode::ExistsJoin);
    ds.relations(true); // Or do ds.addLink(...) etc.
    
    我不确定我是否遵循了正确的逻辑:)

如果需要进行跨公司选择,请使用以下界面:

qbdsRetailTransactionSalesTrans.allowCrossCompany(true);
qbdsRetailTransactionSalesTrans.addCompanyRange('5740');
qbdsRetailTransactionSalesTrans.addCompanyRange('5760');
ds = qbdsRetailTransactionSalesTrans.addDatasource(tableNum(RetailTransactionPaymentTrans));
ds.joinMode(JoinMode::ExistsJoin);
ds.relations(true); // Or do ds.addLink(...) etc.
qbdsRetailTransactionSalesTrans.allowCrossCompany(true);
qbdsRetailTransactionSalesTrans.addCompanyRange('5740');
qbdsRetailTransactionSalesTrans.addCompanyRange('5760');