SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Matching on NULLS


Matching on NULLS

Author
Message
lk4772
lk4772
SSC Veteran
SSC Veteran (226 reputation)SSC Veteran (226 reputation)SSC Veteran (226 reputation)SSC Veteran (226 reputation)SSC Veteran (226 reputation)SSC Veteran (226 reputation)SSC Veteran (226 reputation)SSC Veteran (226 reputation)

Group: General Forum Members
Points: 226 Visits: 132
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 [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


lk4772
lk4772
SSC Veteran
SSC Veteran (226 reputation)SSC Veteran (226 reputation)SSC Veteran (226 reputation)SSC Veteran (226 reputation)SSC Veteran (226 reputation)SSC Veteran (226 reputation)SSC Veteran (226 reputation)SSC Veteran (226 reputation)

Group: General Forum Members
Points: 226 Visits: 132
SORRY! Shouldn't have searched first...just found this post:

[url=http://www.sqlservercentral.com/Forums/Topic687844-8-1.aspx][/url]
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search