Re: Using expressions in a SELECT Clause
From: Tibor Karaszi (tibor_please.no.email_karaszi_at_hotmail.nomail.com)
Date: 02/16/04
- Next message: Sumesh: "Re: Compiling Stored procedures"
- Previous message: Marvin: "Re: Question for Microsoft guys"
- In reply to: William Morris: "Re: Using expressions in a SELECT Clause"
- Next in thread: Shawn Melton: "Re: Using expressions in a SELECT Clause"
- Reply: Shawn Melton: "Re: Using expressions in a SELECT Clause"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 17 Feb 2004 00:45:43 +0100
Watch out for this. The handling of datatype conversion is different in 7.0
and 2000. Code can break when moved from 7.0 to 2000 if you rely on this!
-- Tibor Karaszi, SQL Server MVP Archive at: http://groups.google.com/groups?oi=djq&as_ugroup=microsoft.public.sqlserver "William Morris" <news.remove.this.and.the.dots@seamlyne.com> wrote in message news:c0qp0m$19s4s2$1@ID-205671.news.uni-berlin.de... Although, VB will evaluate a 1 the same as a -1 in boolean terms. "Tom Moreau" <tom@dont.spam.me.cips.ca> wrote in message news:uY43YIK9DHA.1592@TK2MSFTNGP10.phx.gbl... You should be aware that Booleans are not treated the same way throughout industry. For example, IIRC, VB stores a True as -1 while Perl treats it as 1. Using literals avoids the problem. Also, bit datatype are not ANSI standard, so some code could break. -- Tom --------------------------------------------------------------- Thomas A. Moreau, BSc, PhD, MCSE, MCDBA SQL Server MVP Columnist, SQL Server Professional Toronto, ON Canada www.pinnaclepublishing.com/sql "Eric Gnacadja" <wegnac@hotmail.com> wrote in message news:#bzQzCK9DHA.2572@TK2MSFTNGP09.phx.gbl... Sorry for my poor english. I found your solution really nice and wanted to add just the cast to get a bit. I think the user who started the thread wanted to get a boolean. It's nether the last big discovery of the humankind, nor something really different from your solution, just something more which could help. That's what I tried to express, translating a common french expression. Sorry again, "Tom Moreau" <tom@dont.spam.me.cips.ca> a écrit dans le message de news:ecJQ$6J9DHA.488@TK2MSFTNGP12.phx.gbl... I guess I don't understand what you mean by "A little bit forward". -- Tom --------------------------------------------------------------- Thomas A. Moreau, BSc, PhD, MCSE, MCDBA SQL Server MVP Columnist, SQL Server Professional Toronto, ON Canada www.pinnaclepublishing.com/sql "Eric Gnacadja" <wegnac@hotmail.com> wrote in message news:#K15q3J9DHA.2752@TK2MSFTNGP09.phx.gbl... Nice Tom, Nice and simple... A little bit forward: SELECT EmployeeID , cast((case when 4 > 3 then 1 else 0 end ) as bit) As Value FROM Northwind.dbo.Employees Eric "Tom Moreau" <tom@dont.spam.me.cips.ca> a écrit dans le message de news:O4Kf6jJ9DHA.3200@TK2MSFTNGP09.phx.gbl... Try: SELECT EmployeeID , case when 4 > 3 then 'True' else 'False' end As Value FROM Northwind.dbo.Employees -- Tom --------------------------------------------------------------- Thomas A. Moreau, BSc, PhD, MCSE, MCDBA SQL Server MVP Columnist, SQL Server Professional Toronto, ON Canada www.pinnaclepublishing.com/sql "Shawn Melton" <anonymous@discussions.microsoft.com> wrote in message news:7F6A6B4C-BFB1-40AB-9A39-D5FBE0245E22@microsoft.com... According to SQL Server documentation: I can use any expression in a SELECT clause. An expression can consist of two constants separated by a comparison operator. Yet when I try this: SELECT EmployeeID, 4>3 As Value FROM Northwind.dbo.Employees I get the error: Line 1: Incorrect syntax near '>'. Does anyone know why? What I would expect is a two column resultset with a column named Value that is set to false. This is a simplification of what I need but should answer the question. What I really need is to compare a field to a string constant to create a new boolean field.
- Next message: Sumesh: "Re: Compiling Stored procedures"
- Previous message: Marvin: "Re: Question for Microsoft guys"
- In reply to: William Morris: "Re: Using expressions in a SELECT Clause"
- Next in thread: Shawn Melton: "Re: Using expressions in a SELECT Clause"
- Reply: Shawn Melton: "Re: Using expressions in a SELECT Clause"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|