I need to convert the following SQL Select into SQL Update as follows:
SELECT P.Partno, SUM(D.Qty_ordered) - SUM(Qty_rec) as QTY_ONORDER
FROM Parts P
LEFT JOIN PoDet D ON P.Partno = D.Partno
LEFT JOIN PoRec R ON D.PoDet_pk = R.PoDet_pk
GROUP BY P.Partno
I need to update the column ONORDER of the table Parts, setting the value to SUM(D.QTY_Ordered) - SUM(QTY_REC). That is, set the value to the current on-order quantity.
I tried the following (but I get error):
UPDATE P P.ONORDER = SUM(D.Qty_ordered) - SUM(Qty_rec)
FROM Parts P
LEFT JOIN PoDet D ON P.Partno = D.Partno
LEFT JOIN PoRec R ON D.PoDet_pk = R.PoDet_pk
GROUP BY P.Partno
What do I need to change?