or "false". When I use CAST(field1 AS nvarchar(50)) it results in either a
0 or 1. What's the best way using T-SQL to do this?
Thanks,
RynThere is no BOOLEAN type in SQL Server. I assume you mean BIT (this is NOT
BOOLEAN!). A BIT stores 0 or 1, and these values have no correlation to
true or false (except for the cognitive relation *you* make). Try the
following instead of assuming than a conversion to nvarchar(50) will work
magic. BTW, why do you need Unicode and why do you need 50 spaces, when
your outcome is limited to 'true' and 'false'?
SELECT
Field1,
Field1_As_Boolean = CONVERT
(
VARCHAR(5),
CASE field1 WHEN 1 THEN 'true' ELSE 'false' END
)
FROM table_name;
"Ryan" <Tyveil@.newsgroups.nospam> wrote in message
news:OICNDF0BHHA.4348@.TK2MSFTNGP04.phx.gbl...
>I have a boolean field I need to CAST to an nvarchar field of either "true"
>or "false". When I use CAST(field1 AS nvarchar(50)) it results in either a
>0 or 1. What's the best way using T-SQL to do this?
> Thanks,
> Ryn
>|||Use CASE
CASE MyBoo
WHEN 0 THEN 'TRUE'
WHEN 1 THEN 'FALSE'
ELSE 'OOPS'
END
--
Arnie Rowland, Ph.D.
Westwood Consulting, Inc
Most good judgment comes from experience.
Most experience comes from bad judgment.
- Anonymous
You can't help someone get up a hill without getting a little closer to the
top yourself.
- H. Norman Schwarzkopf
"Ryan" <Tyveil@.newsgroups.nospam> wrote in message news:OICNDF0BHHA.4348@.TK2MSFTNGP04.phx.gb
l...
>I have a boolean field I need to CAST to an nvarchar field of either "true"
> or "false". When I use CAST(field1 AS nvarchar(50)) it results in either
a
> 0 or 1. What's the best way using T-SQL to do this?
>
> Thanks,
> Ryn
>
>|||Yes I do mean bit.. old habits die hard

select statement with others that have 50 character nvarchar fields. This
should work, thanks.
"Aaron Bertrand [SQL Server MVP]" <ten.xoc@.dnartreb.noraa> wrote in mess
age
news:ulna7N0BHHA.5068@.TK2MSFTNGP02.phx.gbl...
> There is no BOOLEAN type in SQL Server. I assume you mean BIT (this is
> NOT BOOLEAN!). A BIT stores 0 or 1, and these values have no correlation
> to true or false (except for the cognitive relation *you* make). Try the
> following instead of assuming than a conversion to nvarchar(50) will work
> magic. BTW, why do you need Unicode and why do you need 50 spaces, when
> your outcome is limited to 'true' and 'false'?
> SELECT
> Field1,
> Field1_As_Boolean = CONVERT
> (
> VARCHAR(5),
> CASE field1 WHEN 1 THEN 'true' ELSE 'false' END
> )
> FROM table_name;
>
>
> "Ryan" <Tyveil@.newsgroups.nospam> wrote in message
> news:OICNDF0BHHA.4348@.TK2MSFTNGP04.phx.gbl...
>
No comments:
Post a Comment