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
 General SQL Server Forums
 New to SQL Server Programming
 Combining Columns

Author  Topic 

mea99sdp
Starting Member

1 Post

Posted - 2011-01-29 : 15:15:58
Hello all,

How can I combine 4 columns into a new column. the column types are bit data type.

Rank1,Rank2,Rank3,Rank4
1,1,0,0 = R1R2
1,0,0,1 = R1R4
0,0,1,0 = R3

Many thanks in advance:)

X002548
Not Just a Number

15586 Posts

Posted - 2011-01-29 : 16:08:25
SELECT
CASE WHEN Rank1 = 1 THEN 'R1' ELSE '' END
+ CASE WHEN Rank2 = 1 THEN 'R2' ELSE '' END
+ CASE WHEN Rank3 = 1 THEN 'R3' ELSE '' END
+ CASE WHEN Rank4 = 1 THEN 'R4' ELSE '' END
FROM Table

Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page
   

- Advertisement -