Connecting Tech Pros Worldwide Help | Site Map

Sum up a column and then update a temp table with results

Newbie
 
Join Date: Aug 2007
Posts: 28
#1: Oct 1 '08
I am using SQL 2000. I want to sum up a column and then add that to a newly created table.

How do I do this in SQL Server ? Below is what I am getting the error on:

update #temptable
Set Aug_total = Sum(hist.amount)
Select sum(hist.amount)
from cust inner join hist on
cust.c_id = hist.c_id
where blah blah blah....

The error SQL returns is:
An Aggregate may not appear in the Set list of an Update statement.

How do I get sum totals to put into my temp table?
Member
 
Join Date: Dec 2007
Posts: 81
#2: Oct 2 '08

re: Sum up a column and then update a temp table with results


Is this what you mean?
Expand|Select|Wrap|Line Numbers
  1. update #temptable
  2. Set Aug_total = (
  3. Select sum(hist.amount)
  4. from cust inner join hist on 
  5. cust.c_id = hist.c_id
  6. where blah blah blah....)
Newbie
 
Join Date: Aug 2009
Posts: 4
#3: Aug 23 '09

re: Sum up a column and then update a temp table with results


An aggregate may not appear in the set list of an UPDATE
statement.

I also was struggling with this error

for some days finally i got the solution

Which all i put into my blog


http://sqlerrormessages.blogspot.com...ar-in-set.html
Reply


Similar Microsoft SQL Server bytes