The correct version should be:
IF (@B = @A OR (@B IS NULL AND @A IS NULL)) SELECT 2; ELSE IF (@B != @A OR @B IS NULL OR @A IS NULL) SELECT 1; ELSE SELECT 3;
since NULL comparisons should always be handled separately in SQL.
I inverted the cases != And = because tsql does not have the logical XOR operator, because I want to consider NULL to be NULL.
Note that then SELECT 3 will no longer be.
source share