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 |
|
LearnEveryDay
Starting Member
37 Posts |
Posted - 2005-08-17 : 10:37:18
|
| hello,I have a table has got values id name(varchar) state(bool)1 Question1 12 Question2 03 Question3 14 Question4 1I want the result to be displayed as nameQuestion 1 activated Question2 deactivatedQuestion 3 activated Question 4 activated how will I write the T-Sql query?Thanks, |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2005-08-17 : 10:48:37
|
select name, case when state = 0 then 'activated' when state = 1 then 'deactivated' else 'state not know' end as Statefrom MyTableEdit:a small mistake on my part... fixed in boldGo with the flow & have fun! Else fight the flow |
 |
|
|
LearnEveryDay
Starting Member
37 Posts |
Posted - 2005-08-17 : 10:59:11
|
| well I tried exactly the same way but it throws error " Incorrect syntax near the keyword 'then'. "I dont know why |
 |
|
|
LearnEveryDay
Starting Member
37 Posts |
Posted - 2005-08-17 : 11:06:51
|
| Thanks spritI fiddled around it and it works with the following..... select name, case state when 0 then 'activated' when 1 then 'deactivated' else 'state not know' end as Statefrom MyTablecheers |
 |
|
|
|
|
|