[英]Updating a column in SQL Server with difference in value of some column in another table
您可能需要使用INNER JOIN
連接兩個表
UPDATE t1
SET t1.PendingQty = t1.t1.PendingQty - t2.Invoice.Qty
FROM Table1 t1
INNER JOIN Table2 t2 ON t1.PONumber = t2.PONumber
像這樣的東西:
UPDATE t1
SET t1.[Pending qty] -= ISNULL((SELECT SUM(t2.[Invoice qty])
FROM Table2 AS t2
WHERE t1.[PO Number] = t2.[PO Number]
AND t1.[Part number] = t2.[Part number]), 0);
FROM Table1 AS t1;
我猜測每個待處理表行可能有多個發票行。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.