Help | Site Map
Connecting Tech Pros Worldwide
Reply
 
LinkBack Thread Tools
  #1  
Old October 1st, 2008, 08:15 PM
Newbie
 
Join Date: Aug 2007
Posts: 28
Default Sum up a column and then update a temp table with results

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?
Reply
  #2  
Old October 2nd, 2008, 02:39 AM
Member
 
Join Date: Dec 2007
Posts: 81
Default

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....)
Reply
Reply

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles