Re: Using expressions in a SELECT Clause

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: William Morris (news.remove.this.and.the.dots_at_seamlyne.com)
Date: 02/16/04


Date: Mon, 16 Feb 2004 09:52:34 -0600

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.



Relevant Pages