Results 1 to 4 of 4
  1. #1
    Join Date
    Sep 2005

    Unanswered: Help with SELECT query


    Can someone help me with the following select query as it doesn't seem to bring anything back in the Query Analyzer. I've tried two different methods, but get nothing.

    1st Method
    USE EmployerEngagement
    SELECT On_Stop
    FROM tblEmployer
    WHERE On_Stop = NULL AND Emp_ID IN
       (SELECT Emp_ID
        FROM tblWP_Details
        WHERE Record_ID IN
          (SELECT Record_ID
           FROM tblVetting
           WHERE Next_Vett_Date < GETDATE()))
    2nd Method
    USE EmployerEngagement
    SELECT On_Stop
    FROM tblEmployer INNER JOIN tblWP_Details
    ON tblEmployer.Emp_ID = tblWP_Details.Emp_ID INNER JOIN dbo.tblVetting
    ON tblWP_Details.Record_ID = tblVetting.Record_ID
    WHERE tblEmployer.On_Stop = NULL
    AND tblVetting.Next_Vett_Date < GETDATE()

  2. #2
    Join Date
    Feb 2004
    see "SET ANSI_NULLS" in books online...

    change "where ... = NULL" to "where ... IS NULL"

    and see how you get on..



  3. #3
    Join Date
    Sep 2005
    Thanks, I was just about to reply to say I've figured it out.

    I just realised that the field in question had a default value of 0 not Null.

  4. #4
    Join Date
    Nov 2004
    on the wrong server
    Provided Answers: 6
    but did you get Bill's point about = Null. Nothing equals Null because Null is not a value. it is unknown or the abscence of value. So unless you play with the SQL Server settings, anytime you search for

    SELECT * FROM MyTable WHERE MyField = Null

    you will always get 0 rows.
    “If one brings so much courage to this world the world has to kill them or break them, so of course it kills them. The world breaks every one and afterward many are strong at the broken places. But those that will not break it kills. It kills the very good and the very gentle and the very brave impartially. If you are none of these you can be sure it will kill you too but there will be no special hurry.” Earnest Hemingway, A Farewell To Arms.

Posting Permissions

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