all groups > sql server programming > february 2006 >
You're in the

sql server programming

group:

Casting bit data type to represent something else


Re: Casting bit data type to represent something else David Portas
2/1/2006 1:01:56 PM
sql server programming:
[quoted text, click to view]

SELECT
CASE gender
WHEN 0 THEN 'M'
WHEN 1 THEN 'F'
FROM your_table ;

Fix the column. The proper ISO codes for gender are 0 = Unknown, 1 =
Male , 2 = Female and 9 = Not Applicable so the values for your bit
column are potentially very confusing. Personally I'd use M and F in a
CHAR(1) column.

--
David Portas, SQL Server MVP

Whenever possible please post enough code to reproduce your problem.
Including CREATE TABLE and INSERT statements usually helps.
State what version of SQL Server you are using and specify the content
of any error messages.

SQL Server Books Online:
http://msdn2.microsoft.com/library/ms130214(en-US,SQL.90).aspx
--
Re: Casting bit data type to represent something else Raymond D'Anjou
2/1/2006 2:58:58 PM
Select CASE columnName WHEN 0 THEN 'M' ELSE 'F' END AS gender ...

[quoted text, click to view]

Re: Casting bit data type to represent something else JT
2/1/2006 3:20:54 PM
A bit column is nullable, so we need to adjust the select case like so:

Select CASE columnName WHEN 0 THEN 'M' WHEN 1 THEN 'F' ELSE columnName END
AS gender ...


[quoted text, click to view]

Re: Casting bit data type to represent something else Raymond D'Anjou
2/1/2006 3:33:19 PM
In his post he never mentionned NULL, so I didn't include it.
Maybe the column is not Nullable.
....so there!!! :-|

[quoted text, click to view]

Re: Casting bit data type to represent something else Raymond D'Anjou
2/1/2006 4:09:05 PM
I was just razzing JT for going pedantic on me. :-)

[quoted text, click to view]

Casting bit data type to represent something else Robert Bravery
2/1/2006 10:04:27 PM
HI all,

I have inhereted a table that has a bit datatype with 0 representing Male
gender, and 1 Representing female gender
Is there a way I can cast/convert this to have it display M ... or F in my
select statement

Thanks
Robert

Re: Casting bit data type to represent something else Robert Bravery
2/1/2006 11:09:58 PM
Hi

Thanks a million,
Robert

[quoted text, click to view]

Re: Casting bit data type to represent something else Robert Bravery
2/1/2006 11:10:29 PM
HI,
Yes you are correct. NULL's not allowed

Thanks
Robert

[quoted text, click to view]

Re: Casting bit data type to represent something else Robert Bravery
2/1/2006 11:36:06 PM
Ok. I'm new here so don't know all the politics
:)

Robert

[quoted text, click to view]

Re: Casting bit data type to represent something else Robert Bravery
2/1/2006 11:37:30 PM
Hi David,
Thanks for the reply.
Not my table, inherited it, so stuck with these values
Thanks

Robert

[quoted text, click to view]

AddThis Social Bookmark Button