SQL Update to the SUM of its 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:33 UTC
Read the original article Hit count: 225

Filed under:
|
|

Hi, I'm trying to update a field in the database to the sum of its 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

Related posts about sql

Related posts about update