Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
BobRoberts
Posting Yak Master
109 Posts |
Posted - 2010-02-06 : 16:41:49
|
| I'm trying to calculate a column in one table based on another table. I've tried the following, with the following error.UPDATE b set b.OrderWeight = SUM(a.LineWeight) FROM OrderDetail a JOIN OrderHeader b on a.TransId = b.TransId GOError message: "Msg 157, Level 15, State 1, Line 1An aggregate may not appear in the set list of an UPDATE statement."Here is a representation of the tables involved:OrderHeader table:TRANSID|ORDERWEIGHT-------------------0001 |NULL0002 |NULLOrderDetail table:TRANSID|ENTRY|LINEWEIGHT------------------------0001 |001 |5 0001 |002 |110002 |001 |33After the SQL statement, I would like the OrderHeader table to looklike this:OrderHeader table:TRANSID|ORDERWEIGHT-------------------0001 |160002 |33 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
BobRoberts
Posting Yak Master
109 Posts |
Posted - 2010-02-06 : 17:12:31
|
| Yes, that works beautifully - you've saved my Monday! |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
|
|
|