I am trying to update an invoice total on an invoice table from the lineitem totals on an invoice details table. I'm finding using an aggregate function within an update query is challenging.
I'm adding these total fields to make it easier for management to gather stats in our small firm.
Here is the SQL that I think should work but it not working and throwing a: "Syntax Error (missing operator) in query expression 't.total from tblPO p inner join..."
UPDATE PSET p.PO_total = t.total FROM tblPO p INNER JOIN (SELECT tblPO_Details.PO_ID, SUM(tblPO_Details.subtotal) as total FROM tblPO_Details GROUP BY tblPO_Details.PO_ID) as t ON t.PO_ID = p.PO_ID
I also tried this and it throws "must use updatable query"
UPDATE tblPO INNER JOIN (SELECT tblPO_Details.PO_ID, SUM(tblPO_Details.subtotal) as total FROM tblPO_Details GROUP BY tblPO_Details.PO_ID) as t ON t.PO_ID = tblPO.PO_IDSET tblPO.PO_total = t.total
Open in new window