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 2000 Forums
 SQL Server Development (2000)
 T-Sql query

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 1
2 Question2 0
3 Question3 1
4 Question4 1


I want the result to be displayed as


name

Question 1 activated
Question2 deactivated
Question 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 State
from MyTable

Edit:
a small mistake on my part... fixed in bold

Go with the flow & have fun! Else fight the flow
Go to Top of Page

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
Go to Top of Page

LearnEveryDay
Starting Member

37 Posts

Posted - 2005-08-17 : 11:06:51
Thanks sprit

I 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 State
from MyTable

cheers
Go to Top of Page
   

- Advertisement -