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)
 using case in select query

Author  Topic 

Swati Jain
Posting Yak Master

139 Posts

Posted - 2006-09-18 : 01:38:41
I want to display 'correct ' for boolen field whose value is true and 'incorrect' if its value is false
How to write this using the sql query?

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-09-18 : 01:50:40
[code]
select case when bitcol = 1 then 'correct' else 'incorrect' end
from table
[/code]


KH

Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-09-18 : 02:38:03
Or, if you have allowed NULL value for the boolean field,
select	case
when bitcol = 1 then 'correct'
when bitcol = 0 then 'incorrect'
else 'unknown'
end
from table


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2006-09-18 : 03:47:50
quote:
Originally posted by Peso

Or, if you have allowed NULL value for the boolean field,
select	case
when bitcol = 1 then 'correct'
when bitcol = 0 then 'incorrect'
else 'unknown'
end
from table


Peter Larsson
Helsingborg, Sweden



or more compact syntax:

select	case bitcol 
when 1 then 'correct'
when 0 then 'incorrect'
else 'unknown'
end
from table


Just for the sake of completeness


Harsh Athalye
India.
"Nothing is Impossible"
Go to Top of Page
   

- Advertisement -