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 |
aswindba1
Yak Posting Veteran
62 Posts |
Posted - 2013-04-29 : 17:19:27
|
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
1974 Posts |
Posted - 2013-04-29 : 17:21:08
|
SELECT Server, SUM(Cost) FROM table GROUP BY Server
-Chad |
 |
|
aswindba1
Yak Posting Veteran
62 Posts |
Posted - 2013-04-29 : 17:48:15
|
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. |
 |
|
chadmat
The Chadinator
1974 Posts |
Posted - 2013-04-29 : 17:53:52
|
Add the additional columns into the Group By Clause.
ie
SELECT Server, Billing, SUM(Cost) FROM table GROUP BY Server, Billing
-Chad |
 |
|
aswindba1
Yak Posting Veteran
62 Posts |
Posted - 2013-04-29 : 18:23:38
|
Thanks alot..its working |
 |
|
chadmat
The Chadinator
1974 Posts |
Posted - 2013-04-29 : 18:31:38
|
You are welcome.
-Chad |
 |
|
|
|
|