Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

T-SQL XOR Operator

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

like image 424
ses011 Avatar asked Mar 23 '11 21:03

ses011


People also ask

Is there an XOR operator in SQL?

MySQL XOR operator checks two operands (or expressions) and returns TRUE if one or the other but not both is TRUE.

What is the operator for XOR?

XOR is a bitwise operator, and it stands for "exclusive or." It performs logical operation. If input bits are the same, then the output will be false(0) else true(1).

How do I use XOR code?

The ^ (bitwise XOR) in C or C++ takes two numbers as operands and does XOR on every bit of two numbers. The result of XOR is 1 if the two bits are different. The << (left shift) in C or C++ takes two numbers, left shifts the bits of the first operand, the second operand decides the number of places to shift.

What are bitwise operators in SQL?

Bitwise operators perform bit manipulations between two expressions of any of the data types of the integer data type category. Bitwise operators convert two integer values to binary bits, perform the AND, OR, or NOT operation on each bit, producing a result. Then converts the result to an integer.


1 Answers

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)) 
like image 59
Nathan Rivera Avatar answered Sep 28 '22 12:09

Nathan Rivera