0

我有这个 SQL 语句:

从 AX2009_DEV.dbo.WMSINVENTTRANSDOCK 中选择 * 在 INVENTTRANSREFID 上加入 AX2009_DEV.dbo.SALESTABLE = salesid 在 WMSINVENTTRANSDOCK.inventDimId 上加入 AX2009_DEV.dbo.INVENTDIM = inventDim.inventDimId

我正在尝试用代码写这个:

qbdWMSInventTransDock = query.addDataSource(tableNum(WMSInventTransDock));

qbdSalesTable = qbdWMSInventTransDock.addDataSource(tableNum(SalesTable));
qbdSalesTable.addLink(fieldNum(WMSInventTransDock, InventTransRefId), fieldNum(SalesTable, SalesId));
qbdSalesTable.joinMode(JoinMode::InnerJoin);

qbdInventDim = qbdWMSInventTransDock.addDataSource(tableNum(InventDim));
qbdInventDim.addLink(fieldNum(WMSInventTransDock, InventDimId), fieldNum(InventDim, InventDimId));
qbdInventDim.joinMode(JoinMode::InnerJoin);

但是当我调试时,只要我尝试将 InventDim 连接到 WMSInventTransDock,就可以看到 SQL 语句“重置”。

我想这样做而不是编写选择语句,因为我希望以后能够这样做:

if (inventSiteId)
{
    qbr = qbdInventDim.addRange(fieldNum(InventDim, InventSiteId));
    qbr.value(inventSiteId);
}
if (inventLocationId)
{
    qbr = qbdInventDim.addRange(fieldNum(InventDim, InventLocationId));
    qbr.value(inventLocationId);
}
4

1 回答 1

0

I think you should establish your link/joinmode first, then build your ranges. It might be wise to create separate qbr, qbr2, qbr3 variables too, that way you can reference them, instead of constantly re-initializing the same one...which I wouldn't even think works, but it may since you're applying to the same query. Not a good way to do it at all though.

Try re-arranging the lines like this:

qbdWMSInventTransDock = query.addDataSource(tableNum(WMSInventTransDock));
qbdInventDim = qbdWMSInventTransDock.addDataSource(tableNum(InventDim));
qbdInventDim.joinMode(JoinMode::InnerJoin);
qbdInventDim.addLink(fieldNum(WMSInventTransDock, InventDimId), fieldNum(InventDim, InventDimId));

qbr = qbdWMSInventTransDock.addRange(fieldNum(WMSInventTransDock, ItemId));
qbr.value(_itemId);

qbr = qbdWMSInventTransDock.addRange(fieldNum(WMSInventTransDock, InventTransType));
qbr.value(queryValue(InventTransType::Sales));

qbr = qbdWMSInventTransDock.addRange(fieldNum(WMSInventTransDock, WMSExpeditionStatus));
qbr.value(queryValue(WMSExpeditionStatus::Complete));
于 2013-10-01T21:21:50.727 回答