Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
This select statement gives me totals I'm looking for. Now I want to take those totals and update a different table.
select cus_no,sum(tot_sls_amt)as total_salesfrom oehdrhst_sqlwhere year(inv_dt)=year(getdate()) and month(inv_dt)=month(getdate()) and oehdrhst_sql.orig_ord_type <> 'C'group by cus_no
I want to update Userfield1 in the arcusfil. arcusfil will link to oehdrhst by cus_no
tkizer
Almighty SQL Goddess
38200 Posts
Posted - 2010-10-05 : 14:34:16
Try this:UPDATE aSET Userfield = sum(o.tot_sls_amt)FROM arcusfil aJOIN oehdrhst_sql oON a.cus_no = o.cus_noWHERE year(o.inv_dt)=year(getdate()) and month(o.inv_dt)=month(getdate()) and o.orig_ord_type <> 'C'GROUP BY o.cus_noPlease test it first. Maybe put it into a transaction so that you can rollback if needed.Tara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/Subscribe to my blog
Vack
Aged Yak Warrior
530 Posts
Posted - 2010-10-05 : 14:38:02
Doesn't seem to like where the group by is. Msg 156, Level 15, State 1, Line 5Incorrect syntax near the keyword 'group'.