I need to update newly added column(store the sum of all items of the invoice) with result from subquery which generates more than one rows. I added new column to Invoice table.
ALTER TABLE Invoice
ADD ItemsSum int NULL
I tried following query but it gave error because of multiple results
UPDATE Invoice
SET ItemsSum = (SELECT SUM(Amount)
FROM InvoiceItem it
INNER JOIN Invoice i ON it.InvoiceID = i.ID
GROUP BY i.ID)
How to achieve this correctly in SQL Server?