Matching on NULLS

  • Ok, what am I missing here? I have the following code sample on which I expect one of the queries to return "KEYS DON"T MATCH"...but none of them do? I thought if you were comparing 2 values, and one of them was NULL, it would return a Negative as Null doesn't equal anything? Shouldn't the first 2 comparisons return what I'm wanting? ("KEYS DON"T MATCH")?

    DECLARE @Alternate_Key int = 15122, @key int

    SELECT @Alternate_Key ALT_KEY, @key

    SELECT CASE WHEN @Alternate_Key <> @key

    THEN 'KEYS DON''T MATCH'

    ELSE 'KEYS MATCH'

    END MATCHING_KEYS

    SELECT CASE WHEN @Alternate_Key != @key

    THEN 'KEYS DON''T MATCH'

    ELSE 'KEYS MATCH'

    END MATCHING_KEYS

    SELECT CASE WHEN @Alternate_Key = @key

    THEN 'KEYS DON''T MATCH'

    ELSE 'KEYS MATCH'

    END MATCHING_KEYS

  • SORRY! Shouldn't have searched first...just found this post:

Viewing 2 posts - 1 through 1 (of 1 total)

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