Home Forums SQL Server 2005 T-SQL (SS2K5) Where condition not equal to multiple columns - PUZZLE - who can solve this? RE: Where condition not equal to multiple columns - PUZZLE - who can solve this?

  • Evil Kraig F (1/17/2013)


    *facepalm* sorry about the earlier code. Try this again:

    Alternatively:

    SELECT

    *,

    CASE WHEN column2 <> 'AP' THEN 1 ELSE 0 END AS APtest,

    CASE WHEN column3 <> 'U' THEN 1 ELSE 0 END AS Utest,

    CASE WHEN column2 <> 'AP' AND column3 <> 'U' THEN 1 ELSE 0 END AS APUtest

    FROM

    @Table1

    WHERE

    NOT ( column2 = 'AP' AND column3 = 'U')

    Phil Parkin (1/17/2013)


    --Statement 2

    select * from @Table1

    where (column2 != 'AP' or column3 != 'U')

    For those not versed in boolean logic:

    NOT ( column2 = 'AP' AND column3 = 'U') -->

    NOT(column2 = 'AP') OR NOT(column3 = 'U') -->

    column2 != 'AP' or column3 != 'U'

    Which means: NOT ( column2 = 'AP' AND column3 = 'U') is equivalent to: column2 != 'AP' or column3 != 'U'.