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.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Combining Rows?

Author  Topic 

JeffK627
Yak Posting Veteran

50 Posts

Posted - 2010-06-03 : 13:49:28
I have data that looks like this:

[Date] [Total] [A] [B] [C] [D] [E]
2010-06-02 630 0 0 0 0 4
2010-06-02 630 601 0 0 0 0
2010-06-02 630 0 0 2 0 0
2010-06-02 630 0 7 0 0 0
2010-06-02 630 0 0 0 16 0

I need to combine those rows it so it looks like this:

[Date] [Total] [A] [B] [C] [D] [E]
2010-06-02 630 601 7 2 16 4

Any relatively easy way to do that without a cursor?

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2010-06-03 : 13:52:43
Just sum it up!

SELECT Date,[Total],sum([a]) as A,sum([B]) as B etc.
FRom yourTable
GROUP BY Date,[Total],
Jim

Everyday I learn something that somebody else already knew
Go to Top of Page

JeffK627
Yak Posting Veteran

50 Posts

Posted - 2010-06-03 : 15:10:37
That worked great - thanks! I should have thought of that - need more caffeine...
Go to Top of Page
   

- Advertisement -