我有两张桌子,如下所示:
左表填充了基于列SRNumber
的数据,之后您可以看到表stockrequisition
和表generalinventory
在列{{1}中具有相同的数据}和ItemCode
(左表Qty
)
mySQL命令
RequestedQty
并且该命令位于代码工作的按钮 Update
代码输出
UPDATE GeneralInventory AS tb1
INNER JOIN StockRequisition AS tb2
ON (tb1.ItemCode= tb2.ItemCode)
SET tb1.Qty = Format(tb1.Qty - tb2.RequestedQty,2)
WHERE tb2.SRNumber = 'SR487SHL'
= GeneralInventory.Qty
- GeneralInventory.Qty
其中StockRequisition.RequestedQty
= StockRequisition.SRNumber
和SR487SHL
= GeneralInventory.ItemCode
问题
如何确定StockRequisition.ItemCode
的输出是否为负值,以便我可以停止更新命令。像这样的东西
GeneralInventory.Qty
这是我在VB.Net中的完整代码
if the future output of GeneralInventory.Qty < 0 or Negative then
Msg("Unable to update your request because some of Items Qty will result to Negative,Please review it first")
else
'Do the Update Command
End If
我希望你能得到我,TYSM将来的帮助。
答案 0 :(得分:0)
在我看来,你需要的只是一个额外的WHERE子句
格式(tb1.Qty - tb2.RequestedQty,2)&gt; = 0
答案 1 :(得分:0)
只需使用CASE WHEN
:
UPDATE GeneralInventory AS tb1
INNER JOIN StockRequisition AS tb2
ON (tb1.ItemCode= tb2.ItemCode)
SET tb1.Qty = CASE WHEN tb1.Qty - tb2.RequestedQty < 0 THEN tb1.Qty THEN Format(tb1.Qty - tb2.RequestedQty,2) END
WHERE tb2.SRNumber = 'SR487SHL'
或者您可以使用IF
:
UPDATE GeneralInventory AS tb1
INNER JOIN StockRequisition AS tb2
ON (tb1.ItemCode= tb2.ItemCode)
SET tb1.Qty = IF(tb1.Qty - tb2.RequestedQty < 0, tb1.Qty, Format(tb1.Qty - tb2.RequestedQty,2))
WHERE tb2.SRNumber = 'SR487SHL'
或者你可以这样做:
UPDATE GeneralInventory AS tb1
INNER JOIN StockRequisition AS tb2
ON (tb1.ItemCode= tb2.ItemCode)
SET tb1.Qty = Format(tb1.Qty - tb2.RequestedQty,2)
WHERE tb2.SRNumber = 'SR487SHL'
AND tb1.Qty >= tb2.RequestedQty
如果你想要返回消息,那么你必须创建一个程序。