|
|
 |
 |
 |
 |
BOOLs in SELECT
How can I achieve something like: SELECT somecolumn = 1 AS isequal FROM sometable; thanks !
"Mike Gleason jr Couturier" <mcouturierMAP @bmgmultimedia.com> wrote in message news:C1C1AF3B-21D5-48F3-8AF5-E18F5CE3FE18@microsoft.com... > How can I achieve something like: > SELECT somecolumn = 1 AS isequal > FROM sometable; > thanks !
Sorry I just found it after an hour or so... CASE columnsname WHEN X THEN 1 ELSE 0 END Thanks anyway for reading!
-----------------------------------------------Reply-----------------------------------------------
There are no BOOLEANs in SQL Server. If you want to return the strings 'true' or 'false' to a consuming app, then you can do something like: SELECT IsEqual = CASE WHEN somecolumn = 1 THEN 'true' ELSE 'false' END FROM sometable; If somecolumn is a BIT column, then most apps should understand, and implicitly convert, the fact that 1 = true and 0 = false. -- Aaron Bertrand SQL Server MVP http://www.sqlblog.com/ http://www.aspfaq.com/5006 "Mike Gleason jr Couturier" <mcouturierMAP@bmgmultimedia.com> wrote in message news:C1C1AF3B-21D5-48F3-8AF5-E18F5CE3FE18@microsoft.com...
> How can I achieve something like: > SELECT somecolumn = 1 AS isequal > FROM sometable; > thanks !
On Jun 4, 2:04 pm, "Aaron Bertrand [SQL Server MVP]" <ten. @dnartreb.noraa> wrote: > There are no BOOLEANs in SQL Server. If you want to return the strings > 'true' or 'false' to a consuming app, then you can do something like: > SELECT IsEqual = CASE > WHEN somecolumn = 1 THEN 'true' > ELSE 'false' > END > FROM sometable; > If somecolumn is a BIT column, then most apps should understand, and > implicitly convert, the fact that 1 = true and 0 = false.
Unfortunately, MS Access, Excel, and other VBA-based apps will instead do a double translation of 1 -> true -> -1, which leads to some unfortunate confusion. -----------------------------------------------Reply-----------------------------------------------
That's why it is good practice to always test for False: '= False' Or '<> False' Rather than: '<> True' Or '= True' MH "rpresser" <rpres @gmail.com> wrote in message news:1180986665.268515.100720@p47g2000hsd.googlegroups.com...
> On Jun 4, 2:04 pm, "Aaron Bertrand [SQL Server MVP]" > <ten. @dnartreb.noraa> wrote: >> There are no BOOLEANs in SQL Server. If you want to return the strings >> 'true' or 'false' to a consuming app, then you can do something like: >> SELECT IsEqual = CASE >> WHEN somecolumn = 1 THEN 'true' >> ELSE 'false' >> END >> FROM sometable; >> If somecolumn is a BIT column, then most apps should understand, and >> implicitly convert, the fact that 1 = true and 0 = false. > Unfortunately, MS Access, Excel, and other VBA-based apps will instead > do a double translation of 1 -> true -> -1, which leads to some > unfortunate confusion.
I concur. Or (with bits) = 0 or <> 0 ......... "MH" <n @nohow.com> wrote in message news:eJUN8supHHA.1220@TK2MSFTNGP03.phx.gbl...
> That's why it is good practice to always test for False: > '= False' Or '<> False' > Rather than: > '<> True' Or '= True' > MH > "rpresser" <rpres@gmail.com> wrote in message > news:1180986665.268515.100720@p47g2000hsd.googlegroups.com... >> On Jun 4, 2:04 pm, "Aaron Bertrand [SQL Server MVP]" >> <ten.@dnartreb.noraa> wrote: >>> There are no BOOLEANs in SQL Server. If you want to return the strings >>> 'true' or 'false' to a consuming app, then you can do something like: >>> SELECT IsEqual = CASE >>> WHEN somecolumn = 1 THEN 'true' >>> ELSE 'false' >>> END >>> FROM sometable; >>> If somecolumn is a BIT column, then most apps should understand, and >>> implicitly convert, the fact that 1 = true and 0 = false. >> Unfortunately, MS Access, Excel, and other VBA-based apps will instead >> do a double translation of 1 -> true -> -1, which leads to some >> unfortunate confusion.
|
 |
 |
 |
 |
|