WHERE Condition only if a column is not NULL

  • Having a real memory lapse. I have a recordset that's based on an outer join, no problem. BUT one of the tests in the WHERE statement is against a column that could be NULL as a result of the outer join set.

    I want to perform the WHERE test only if the offending column is not null. I'm sure I can do it but I just don't know how.

    Any ideas....

    I have found it is possible to please all of the people all of the time if you do exactly what they want. Harold Macmillan 1961


    I have found it is possible to please all of the people all of the time if you do exactly what they want. Harold Macmillan 1961

  • select * from orders where shipregion is not null

  • Didn't explain myself properly

    SELECT * from [tablename]

    LEFT OUTER JOIN [tablename2].......

    WHERE [tablename.fldname_1] = [value]

    AND [tablename.fldname_2] > [tablename2.fldname] (ONLY IF tablename.fldname is not null)

    I have found it is possible to please all of the people all of the time if you do exactly what they want. Harold Macmillan 1961


    I have found it is possible to please all of the people all of the time if you do exactly what they want. Harold Macmillan 1961

  • Try including it in your join rather than the where.

    Andy

    http://www.sqlservercentral.com/columnists/awarren/

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply