Home All Groups Group Topic Archive Search About

Need to return a column with '1' and '0' value as 'Active' or 'Disabled'

Author
22 Sep 2005 9:50 PM
Robert G via SQLMonster.com
Hello,

I'm running a simple query that has a field named "Active".  The "Active"
field has either a value of "1" or "0" ('active' or 'disabled').

However, instead of returning a "1" or "0" (values stored in the db) I need
to return "Active" or "Disabled" based on a simple IF statement.  I don't
know how to do this with SQL.

Can someone help??!! 

Thank you



Author
22 Sep 2005 9:54 PM
Anith Sen
Lookup CASE expressions in SQL Server Books Online.

--
Anith
Author
22 Sep 2005 9:57 PM
Jerry Spivey
Robert,

Try:

select case val
  when 0 then 'Disabled'
  when 1 then 'Enabled'
    end AS 'Active'
from yourtable


Show quote
"Robert G via SQLMonster.com" <fo***@SQLMonster.com> wrote in message
news:54C39E96AECB4@SQLMonster.com...
> Hello,
>
> I'm running a simple query that has a field named "Active".  The "Active"
> field has either a value of "1" or "0" ('active' or 'disabled').
>
> However, instead of returning a "1" or "0" (values stored in the db) I
> need
> to return "Active" or "Disabled" based on a simple IF statement.  I don't
> know how to do this with SQL.
>
> Can someone help??!!
>
> Thank you
>
>
> --
> Message posted via SQLMonster.com
> http://www.sqlmonster.com/Uwe/Forums.aspx/sql-server-programming/200509/1
Author
26 Sep 2005 7:41 PM
Robert G via SQLMonster.com
Thanks Guys, your responses were very helpful!!!

Jerry Spivey wrote:
Show quote
>Robert,
>
>Try:
>
>select case val
>  when 0 then 'Disabled'
>  when 1 then 'Enabled'
>    end AS 'Active'
>from yourtable
>
>> Hello,
>>
>[quoted text clipped - 9 lines]
>>
>> Thank you


Author
22 Sep 2005 9:57 PM
Yosh
SELECT

CASE Active WHEN 1 THEN 'Active' ELSE 'Disabled' END

FROM <TableName>



Show quote
"Robert G via SQLMonster.com" <fo***@SQLMonster.com> wrote in message
news:54C39E96AECB4@SQLMonster.com...
> Hello,
>
> I'm running a simple query that has a field named "Active".  The "Active"
> field has either a value of "1" or "0" ('active' or 'disabled').
>
> However, instead of returning a "1" or "0" (values stored in the db) I
> need
> to return "Active" or "Disabled" based on a simple IF statement.  I don't
> know how to do this with SQL.
>
> Can someone help??!!
>
> Thank you
>
>
> --
> Message posted via SQLMonster.com
> http://www.sqlmonster.com/Uwe/Forums.aspx/sql-server-programming/200509/1
Author
22 Sep 2005 10:02 PM
Trey Walpole
see CASE

CASE [Active] WHEN '1' THEN 'Active' WHEN '0' THEN 'Disabled' ELSE
'Unknown' END

Does this column really have a character datatype (char,varchar)?

Robert G via SQLMonster.com wrote:

Show quote
>Hello,
>
>I'm running a simple query that has a field named "Active".  The "Active"
>field has either a value of "1" or "0" ('active' or 'disabled').
>
>However, instead of returning a "1" or "0" (values stored in the db) I need
>to return "Active" or "Disabled" based on a simple IF statement.  I don't
>know how to do this with SQL.
>
>Can someone help??!! 
>
>Thank you
>
>

>

AddThis Social Bookmark Button