|
database
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Need to return a column with '1' and '0' value as 'Active' or 'Disabled'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 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 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 -- Message posted via SQLMonster.com http://www.sqlmonster.com/Uwe/Forums.aspx/sql-server-programming/200509/1 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 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 > > > > |
|||||||||||||||||||||||