retrieving NULL values with <> 'XYZ' in clauses

  • Here is a where clause:

    WHERE CDAPEN <> 'P'

    I need to retrieve all rows with CDAPEN <> 'P' even if CDAPEN is NULL.

    I would'nt use ISNULL(CDAPEN,'') function because we have a lot of column in this case and some of them are in DATETIME format.

    Thank in advance for all answers.

  • Benoit ,

    the best way to go about this would be using

    ((Col <> 'XYZ' ) AND (Col IS NULL)) in the where clause

    this would utilize any indexes on the Column

    ISNULL would probably make the where clause unsargeable ,

    but you can get around the datetime issue by using

    ISNULL(Col,DATEADD(dd,1,@DateVar)) = @DateVar

    the SET ANSI_NULLS OFF option wouldnt work for you

  • Actually should be

    ((Col <> 'XYZ' ) OR (Col IS NULL)) so it can

    be either situation or

    COL != 'XYZ'

    does the same.

    "Don't roll your eyes at me. I will tape them in place." (Teacher on Boston Public)

  • Antares,

    you are right it should be OR instead of AND , my mistake

    and it should be ISNULL(Col,DATEADD(dd,1,@DateVar)) <> @DateVar

    but did not understand what you mean by

    quote:


    COL != 'XYZ'

    does the same.


  • != means not equal, NULL is not equal in comparison thus

    Col != 'XYZ' will look for anything that does not equal 'XYZ'.

    "Don't roll your eyes at me. I will tape them in place." (Teacher on Boston Public)

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

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