SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 SSIS and Import/Export (2008)
 Query Help
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

aswindba1
Yak Posting Veteran

USA
62 Posts

Posted - 04/29/2013 :  17:19:27  Show Profile  Reply with Quote
I need add multiple rows and take sum of that row in to single column


Server|||| Cost

abcd ||||| 75
abcd ||||| 25
dtgr ||||| 65
dtgr ||||| 35

table should lok like below.

Server||||| Cost
abcd ||||| 100
abcd ||||| 100
dtgr ||||| 100
dtgr ||||| 100

or

abcd |||||100
dtgr |||||100

chadmat
The Chadinator

USA
1974 Posts

Posted - 04/29/2013 :  17:21:08  Show Profile  Visit chadmat's Homepage  Reply with Quote
SELECT Server, SUM(Cost)
FROM table
GROUP BY Server

-Chad
Go to Top of Page

aswindba1
Yak Posting Veteran

USA
62 Posts

Posted - 04/29/2013 :  17:48:15  Show Profile  Reply with Quote
Hi Thanks for the reply..but when I am selecting the mutiple rows I am geting the follwoing error.

Msg 8120, Level 16, State 1, Line 2
Column 'Billing' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
Go to Top of Page

chadmat
The Chadinator

USA
1974 Posts

Posted - 04/29/2013 :  17:53:52  Show Profile  Visit chadmat's Homepage  Reply with Quote
Add the additional columns into the Group By Clause.

ie

SELECT Server, Billing, SUM(Cost)
FROM table
GROUP BY Server, Billing

-Chad
Go to Top of Page

aswindba1
Yak Posting Veteran

USA
62 Posts

Posted - 04/29/2013 :  18:23:38  Show Profile  Reply with Quote
Thanks alot..its working
Go to Top of Page

chadmat
The Chadinator

USA
1974 Posts

Posted - 04/29/2013 :  18:31:38  Show Profile  Visit chadmat's Homepage  Reply with Quote
You are welcome.

-Chad
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.69 seconds. Powered By: Snitz Forums 2000