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)
 summarize mulitple column values/rows into one

Author  Topic 

Cathryn
Starting Member

4 Posts

Posted - 2009-02-18 : 19:29:02
have a table

Col1 Col2 Col3 Col4 Col5
----- ------ ------ ----- ------
1 abc NULL NULL NULL
1 NULL def NULL NULL
1 NULL NULL ghi NULL
1 NULL NULL NULL jkl

I want:

Col1 Col2 Col3 Col4 Col5
----- ------ ------ ----- ------
1 abc def ghi jkl

At first I thougt I could use pivot which I'm not sure how to do that but then I started doubting that. Any help would be great!

Thanks~!

SQLforGirls
Starting Member

48 Posts

Posted - 2009-02-18 : 19:31:43
If it's truly as simple as that, you should be able to use MAX()

select col1,
max(col2),
max(col3),
max(col4),
max(col5)
from Table1
group by col1

Hope that helps.
Go to Top of Page

Cathryn
Starting Member

4 Posts

Posted - 2009-02-18 : 20:12:23
Ok - I feel completely stupid. I thought I tried that and got an error b/c my values weren't integers..I must have been staring at it too long...making something simple too difficult.

Thanks!
Go to Top of Page
   

- Advertisement -