Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Matching on NULLS Expand / Collapse
Author
Message
Posted Thursday, October 3, 2013 4:45 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Friday, July 25, 2014 5:26 PM
Points: 15, Visits: 80
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

Post #1501379
Posted Thursday, October 3, 2013 4:48 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Friday, July 25, 2014 5:26 PM
Points: 15, Visits: 80
SORRY! Shouldn't have searched first...just found this post:

[url=http://www.sqlservercentral.com/Forums/Topic687844-8-1.aspx][/url]
Post #1501380
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse