difference between IS NULL and = NULL

  • I altered a sql script the other day to handle for a column containing NULLs. Basically, in the case of a NULL I wanted the value 'Other' to take its' place.

    When I gave the condition = NULL, the NULLs remained. When I gave the condition IS NULL then the NULLS were replaced with the value 'Other' as was desirable.

    So far I have only come up with the following link when googling: http://www.sqlservercentral.com/articles/T-SQL/understandingthedifferencebetweenisnull/871/ and it refers to setting variables to NULL and memory allocation.

    Can someone explain difference between IS NULL and = NULL when using conditional statements?

  • KoldCoffee (5/22/2013)


    I altered a sql script the other day to handle for a column containing NULLs. Basically, in the case of a NULL I wanted the value 'Other' to take its' place.

    When I gave the condition = NULL, the NULLs remained. When I gave the condition IS NULL then the NULLS were replaced with the value 'Other' as was desirable.

    So far I have only come up with the following link when googling: http://www.sqlservercentral.com/articles/T-SQL/understandingthedifferencebetweenisnull/871/ and it refers to setting variables to NULL and memory allocation.

    Can someone explain difference between IS NULL and = NULL when using conditional statements?

    Think of NULL as "I don't know"

    = NULL

    Does the value in my column match a value that I don't know?

    Answer: I don't know

    IS NULL

    Is the value in my column a value that I don't know?

    Answer: Yes

    The SQL Guy @ blogspot[/url]

    @SeanPearceSQL

    About Me[/url]

  • Sean has the best explanation I could give. When testing for a null value, you want to use "Is Null", or INULL() or COALESCE(). Those are functions designed to work with null values.

    = NULL is unknown. It could be equal; it could not.

  • Thank you Sean and Steve!

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

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