Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
(CASE A WHEN THEN ELSE END AS 'A1' + ' ' +CASE B WHEN THEN ELSE END AS 'B1') AS A1 + ' ' + B1
nathans
Aged Yak Warrior
938 Posts
Posted - 2010-10-10 : 13:48:27
What is your question?
TansRYA
Starting Member
3 Posts
Posted - 2010-10-10 : 14:17:12
that would help!!!... How do i combine case statements. I want to be able to alias each column as well as combine them into another column.
TansRYA
Starting Member
3 Posts
Posted - 2010-10-10 : 14:39:19
Example I have a table that has the following columns[Column1][Column2]the above columns are boolean, to start with i want to return 0=NULL and 1=Dog plus i want to alias each column i.e. Col1 and Col2then i want to combine Col1 and Col2 and alias this as 'Animals' as well as returning Col1 and Col2 in the query.I should be left withCol1 Col2 AnimalsDog NULL DogNULL Cat CatDog Cat Dog, Cat
nathans
Aged Yak Warrior
938 Posts
Posted - 2010-10-10 : 22:50:50
ok, I think I understand. Does this work for you?
select Col1, Col2, coalesce(Col1, Col2) [Animals]from ( select case Column1 when 0 then null when 1 then 'Dog' end [Col1], case Column2 when 0 then null when 1 then 'Dog' end [Col2] from @t ) d(Col1, Col2)