equivalent postgresql syntax
-- MS SQL way
UPDATE Item
SET Qty = ISNULL(X.SumQty,0)
FROM Item
LEFT JOIN
(
SELECT ItemCode, SUM(TranItem.Qty) AS SumQty
FROM TranItem
GROUP BY ItemCode
) AS X
ON X.ItemCode = Item.ItemCode
-- Postgres way
UPDATE Item
SET Qty = X.SumQty
FROM
(
SELECT Item.ItemCode, COALESCE(SUM(TranItem.Qty),0) AS SumQty
FROM Item
LEFT JOIN TranItem
ON TranItem.ItemCode = Item.ItemCode
GROUP BY Item.ItemCode
) AS X
WHERE X.ItemCode = Item.ItemCode
0 Comments:
Post a Comment
<< Home