Results 1 to 5 of 5
  1. #1
    Join Date
    Feb 2004
    Location
    Australia
    Posts
    183

    Question Unanswered: Basic select statement question

    If I want to select certain values from a table where date is equal to something and the second field is null,would I go.

    select * from table where date = 'something' and Sent = null or something else because if I do it this way I get nothing as a result but if I scroll down I can see that I have null values.

    thanks

  2. #2
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    NULL is a tricky beast, because nothing ever equals NULL, not even NULL itself. You need to modify your statement slightly to use a semantically different test, like:
    Code:
    SELECT *
       FROM table
       WHERE date = 'something'
          AND Sent IS null
    This seems like a trivial difference, and from a coding perspective it is. From the logical perspective however, the difference is huge.

    -PatP

  3. #3
    Join Date
    Feb 2004
    Location
    Australia
    Posts
    183
    Ooh,that made all the difference, I always say, it is easy once you know how to do it.
    Thanks for you help once again

  4. #4
    Join Date
    Apr 2004
    Location
    Kansas City, MO
    Posts
    734
    Since you're dealing with this, you might want to look up ANSI_NULLS in Book Online and memorize it. It will save you a lot of pain down the road. Make sure you use SET ANSI_NULLS ON when creating tables and procedures.
    MeanOldDBA
    derrickleggett@hotmail.com
    When life gives you a lemon, fire the DBA.

  5. #5
    Join Date
    Feb 2004
    Location
    Australia
    Posts
    183
    Will do so,thanks

Posting Permissions

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