I must to check if two values, X and Y are different. If both are null, they must be considered as equal.
The unique way I found is:
select 1 as valueExists
where (@X is null and @Y is not null)
or (@Y is null and @X is not null)
or (@X <> @Y)
Is there a smart way to write this expression? Thanks!
SELECT 1 as valuesDifferent WHERE EXISTS (SELECT @X EXCEPT SELECT @Y). The answer you accepted doesn't work correctly forSET @X = ''; SET @Y = NULLwhere existsreturns true if the sub query it contains returns a row. This will happen in this case if the two values are distinct. Treatingnullas a distinct value