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 |
|
theladycoder
Starting Member
16 Posts |
Posted - 2008-08-14 : 13:05:24
|
| I am trying to calculate qtyOnHand in one table based on a product number, which is stored in the field prodNum. I want the calculation to be a grand total for each distinct product number, which then updates another table based on product numbers.If I run the following script the results are what I am looking for:select sum(qty_on_hand) as TotalQty, prodNumfrom table1where prodNum= prodNumgroup by prodNumNow when I want to take this to an update statement, but what I have tried has not worked. Here are the couple of ways that I have tried:Update table2set table2.TxnQty = table1.qty_on_handselect sum(table1.qty_on_hand) as TotalQty, table1.prodNumfrom table1, table2where table1.prodNum= table2.prodNumI have even tried an inner join to update this table, but no luck. Any ideas? I am working in SQL 2005. thanks in advance. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-08-14 : 13:41:02
|
| [code]Update t2set t2.TxnQty =t1.TotalQtyfrom table2 t2inner join (select sum(qty_on_hand) as TotalQty, prodNumfrom table1group by prodNum)t1on t1.prodNum=t2.prodNum[/code] |
 |
|
|
|
|
|