这是我目前的查询:
SELECT i.itemNo, Nz(TotalOrdered,0) AS Sumofqtyordered, Nz(TotalReturned,0) AS sumofqtyreturn, Nz(TotalIssued,0) AS sumofqtyissued, (Nz(TotalOrdered,0)-Nz(TotalIssued,0)-Nz(TotalReturned,0)) AS Balance
FROM ((item AS i
LEFT JOIN (SELECT itemno, Sum(qtyordered) AS TotalOrdered FROM delivered_item GROUP BY itemno) AS d ON d.itemno=i.itemno)
LEFT JOIN (SELECT itemno, Sum(qtyreturn) AS TotalReturned FROM item_return GROUP BY itemno) AS r ON r.itemno=i.itemno)
LEFT JOIN (SELECT itemno, Sum(qtyissued) AS TotalIssued FROM item_issued GROUP BY itemno) AS iss ON iss.itemno=i.itemno;
如何将项目表中的字段(minqty)与查询中的余额进行比较?我将在此查询中再添加一个字段PlaceOrder(布尔值)。当余额小于minqty时设置为yes,当它大于或等于minqty时设置为yes?任何1可以帮助我的代码吗?
答案 0 :(得分:0)
将此添加到您的SELECT
:
((Nz(TotalOrdered,0)-Nz(TotalIssued,0)-Nz(TotalReturned,0))<[minqty]) AS PlaceOrder
它将返回-1(True)或0(False)。如果您希望它实际返回“是”或“否”:
IIf((Nz(TotalOrdered,0)-Nz(TotalIssued,0)-Nz(TotalReturned,0))<[minqty],'Yes','No') AS PlaceOrder