I am trying to write a T-SQL statement that will compare two nullable variables (either int or varchar), @x and @y, and return FALSE if both values are equal or both values are equal to NULL, and return TRUE otherwise. A and B are both placeholders for possible values.
+------+------+--------+
| @x   | @y   | Result |
+------+------+--------+
| NULL | NULL | False  |
| A    | A    | False  |
| B    | A    | True   |
| A    | B    | True   |
| NULL | A    | True   |
| A    | NULL | True   |
+------+------+--------+
I can use COALESCE(@x,@y) to verify that both @x and @y are NULL. Since no value can ever be equal to (or not equal to) NULL, I cannot use <> or = operators. What would be the most compact way to write such statement? Do I have to state a bunch of conditions, such as: (@x is not NULL and @y is not null and @x <> @y)  or (@x is not null and @y is null) or (@x is null and @y is not null)?

(@x is not NULL and @y is not null and @x <> @y)in a where clause to ensure sargability.