T-SQL XOR Operator

ses011 picture ses011 · Mar 23, 2011 · Viewed 109k times · Source

Is there an XOR operator or equivalent function in SQL Server (T-SQL)?

Answer

Nathan Rivera picture Nathan Rivera · Mar 23, 2011

There is a bitwise XOR operator - the caret (^), i.e. for:

SELECT 170 ^ 75

The result is 225.

For logical XOR, use the ANY keyword and NOT ALL, i.e.

WHERE 5 > ANY (SELECT foo) AND NOT (5 > ALL (SELECT foo))