October 17, 2012 at 12:41 pm
I want to select a field that has a value of 0 or 1. I want to select that field but have it print
FALSE for a value of 0
TRUE for a value of 1
October 17, 2012 at 12:46 pm
The straightforward way is:
SELECT
CASE WHEN column_name = 0 THEN 'FALSE' ELSE 'TRUE' END AS column_name
The "avoid a CASE at all costs" way is:
SELECT
SUBSTRING('FALSETRUE', 1 + column_name * 5, 5) AS column_name
SQL DBA,SQL Server MVP(07, 08, 09) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".
October 17, 2012 at 12:47 pm
jon.wilson (10/17/2012)
I want to select a field that has a value of 0 or 1. I want to select that field but have it printFALSE for a value of 0
TRUE for a value of 1
You should really leave this type of thing to the front end. But if you must do it in sql you can use a case expression easily for this.
case MyBitColumn when 1 then 'True' when 0 then 'False' end
If this column is nullable you probably need to add an else to the case to handle null.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
October 17, 2012 at 1:00 pm
Thanks, that did the trick..
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply