SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    Knowledge is key 2 progression Tryst's Avatar
    Join Date
    Sep 2003
    Location
    Wales
    Posts
    1,181
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Condition Statement - MS SQL

    Hi all,

    I have a question to ask about how SQL SERVER evaluates the condition of a statement.

    If I have the following WHERE clause statement...

    Code:
    WHERE ((loadout IS NULL) OR (loadout = '')) AND ((cancout IS NULL) OR (cancout = ''))
    ... I want to only return rows that have either a NULL value of an empty string value in the loadout field/column AND the cancout column also contains either a NULL value or an empty string. Does this WHERE clause do what I have just descriped?

    Thanks

    Tryst

  2. #2
    SitePoint Guru
    Join Date
    Jan 2004
    Location
    Uppsala, sverige
    Posts
    697
    Mentioned
    2 Post(s)
    Tagged
    1 Thread(s)
    Yes.

  3. #3
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,260
    Mentioned
    60 Post(s)
    Tagged
    3 Thread(s)
    yes it does

    you could also write
    Code:
    WHERE coalesce(loadout,'') = '' 
      AND coalesce(cancout,'') = ''
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  4. #4
    Knowledge is key 2 progression Tryst's Avatar
    Join Date
    Sep 2003
    Location
    Wales
    Posts
    1,181
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, thanks guys.

    I will have to check out that coalesce function, as I haven't seen that before.

    Tryst


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •