SQL Update to the SUM if it's joined values
Posted
by CL4NCY
on Stack Overflow
See other posts from Stack Overflow
or by CL4NCY
Published on 2010-03-23T17:13:42Z
Indexed on
2010/03/23
17:23 UTC
Read the original article
Hit count: 287
Hi, I'm trying to update a field in the database to the sum of it's joined values:
UPDATE P
SET extrasPrice = SUM(E.price)
FROM dbo.BookingPitchExtras AS E
INNER JOIN dbo.BookingPitches AS P ON E.pitchID = P.ID
AND P.bookingID = 1
WHERE E.[required] = 1
When I run this I get the following error:
"An aggregate may not appear in the set list of an UPDATE statement."
Any ideas?
© Stack Overflow or respective owner