sql - TSQL Comparing 2 uniqueidentifier values not working as expected -


i'm trying compare 2 uniqueidentifier values shown in query below. however, if 1 value null , 1 value isn't, result 'same'?! i'm sure both values uniqueidentifiers, , have tried casting both values uniqueidentifier make absolutely sure. 2 values being compared coming different databases different collations. collation make difference? ideas appreciated.

select [result] = case when      [target].staffid <> [source].staffid 'different'      else 'same'      end     ... 

if replace <> = query thinks 2 null values don't match.

edit:

i used:

declare @empty uniqueidentifier set @empty = '00000000-0000-0000-0000-000000000000' ... isnull(somevalue, @emtpy) <> isnull(othervalue, @empty) ... 

null neither equal nor equal nothing. you'd check null values comparing is null. example,

somefield null 

you using coalesce you're trying -- make sure use same data types (in case uniqueidentifier):

...   case      when coalesce(t.staffid,'00000000-0000-0000-0000-000000000000') <>           coalesce(t2.staffid,'00000000-0000-0000-0000-000000000000')     'different'      else 'same'    end ... 

http://sqlfiddle.com/#!3/181e9d/1


Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -