Re: pseudo code to convert decimal to boolean and vice versa
Tech-Archive recommends: Fix windows errors by optimizing your registry
On Tue, 23 Jun 2009 14:21:57 -0700, RR wrote:
I would like to convert a decimal to boolean. How can I do so ? Also need
the vice versa solution.
In addition, are there any inbult SQL functions to do so already ?
Either way, I still want to see the logic on doing the conversion even if a
SQL function already exists.
Thanks
Hi RR,
SQL Server does not have a boolean type. Do you mean bit?
You can use both implicit or explicit conversions. All decimal values
except 0.0 will be converted to the bit value 1. For the other way
around, the bit values 0 and 1 will be converted to the decimal vallues
0.0 and 1.0 respectively.
If you want to do this yourself, you can use a CASE expression:
decimal to bit:
CASE WHEN @decimal = 0.0 THEN 0 ELSE 1 END
bit to decimal:
CASE WHEN @bit = 0 THEN 0.0 ELSE 1.0 END
But I fail to see why you'd do this. There is absolutely no benefit in
this.
--
Hugo Kornelis, SQL Server MVP
My SQL Server blog:
http://sqlblog.com/blogs/hugo_kornelis
.
Relevant Pages
- Re: Error "SQL Server does not allow remote connections"
... The application could not connect to the sql server db. ... network is blocking the connection. ... SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 ... integratedSecurity, SqlConnection owningObject) +737554 ... (microsoft.public.dotnet.framework.aspnet) - Re: Sql 2005: SSIS - How to convert "N/Y" CHAR(1) to byte type column
... below) to represent boolean types. ... i.e. an expression that takes a charconstruction_weld column value from the flat file and converts it to a bit type that is compatible with the construction_weld column in the wl_well_casing_liner table. ... > Before we go further on the issue, I'd like to know which data type you> want to use in SQL server, do you use any tinyint? ... I'm totally unfamiliar the grammar of SSIS expressions> and I ... (microsoft.public.sqlserver.dts) - Re: Custom membership provider problem
... SQL server 2005 does not install with the TCP/IP protocol turned on. ... >An error has occurred while establishing a connection to the server. ... 25 - Connection string is not valid) ... >Boolean& failoverDemandDone, String host, String failoverPartner, String ... (microsoft.public.dotnet.framework.aspnet) - Re: Select statement for boolean and/or DateTime values?
... The above works for an SQL Server, means reader contains the row I'm ... SQL Server does not have a boolean datatype, and even if it did, ... Access DOES have a boolean datatype, but, it requires a nonstandard ... Again, if you utilize parameters, values will be passed correctly to the Jet ... (microsoft.public.data.ado) - Re: Access Boolean to SqlServer???
... And I fall in-between Mark and Ken... ... I try to decide what is the primary function for the boolean... ... Wayne Snyder, MCDBA, SQL Server MVP ... (microsoft.public.sqlserver.server) |
|