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 |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2002-03-05 : 09:01:49
|
| gman writes "updating a table from another table here's some codeUPDATE Orders SET TotalSales = (SELECT UnitPrice, Quantity FROM OrderDetails WHERE Orders.OrderID = OrderDetails.OrderID AND OrderDetails.UnitPrice * OrderDetails.Quantity)any help would be greatly appreciated......gmanusing SQL 2000" |
|
|
izaltsman
A custom title
1139 Posts |
Posted - 2002-03-05 : 09:16:10
|
Not quite sure what you are trying to do, but I'm guessing you just want to calculate order total and stick it into the Orders table. So your query will look something like this: UPDATE oSET o.TotalSales = od.ttlFROM Orders o INNER JOIN (SELECT OrderID, SUM(UnitPrice*Quantity) as ttl FROM OrderDetails GROUP BY OrderID) od ON o.OrderID = od.OrderID |
 |
|
|
|
|
|