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 |
|
silentthread
Starting Member
2 Posts |
Posted - 2008-01-24 : 16:03:50
|
| Hi,I'm new to the forum, and semi new to sql, I've been working withit for about 1 year now, but from a programmers side. I simplyjust plug in my selects, and inserts, but most of my work is inasp.net. I apologize if I have posted in the wrong forum section.Here is my problem....I have a table that has the follwing columns..UserName, question1, question2, Idquestion1 and question2 columns simply hold either 'Y' or 'N'Meaning that the user either answered Y or N for the questions.I'm trying to create another column on the fly... example....select *,[othercolumn] = case question1when 'Y' then 'question1,'else ''endfrom mytableIf both questions1 and questions2 have the column value of 'Y', thenthe othercolumn should have 'question1,question2' as the end of the above select.The above example only works for checking for question1, but I will needto do the same for question2 and concatinate that into the othercolumn column.I hope, I have explained myself well.Please let me know if you need more info from me. |
|
|
jdaman
Constraint Violating Yak Guru
354 Posts |
Posted - 2008-01-24 : 16:23:29
|
| [code]SELECT CASE WHEN question1 = 'Y' THEN CASE WHEN question2 = 'Y' THEN 'question1, question2' ELSE 'question1' END WHEN question2 = 'Y' THEN 'question2' ELSE '' END[/code] |
 |
|
|
raaj
Posting Yak Master
129 Posts |
Posted - 2008-01-24 : 16:33:35
|
| i am not sure whether this is correct or not...just trying....select *, othercolumn = case when question1 ='Y' and question2 = 'Y' then question1+','+question2 end ur output will be something like this under othercolumn Y,Yif u want ur output to be question1,question...then u can try this...select *, othercolumn = case when question1 ='Y' and question2 = 'Y' then 'question1,question2' end is tht the one which ur looking for??? |
 |
|
|
silentthread
Starting Member
2 Posts |
Posted - 2008-01-25 : 13:23:22
|
| Thanks, this is awesome. I did not know about nesting SQL. |
 |
|
|
|
|
|
|
|