Microsoft® SQL Server® 2012 Bible

(Ben Green) #1

180


Part II: Building Databases and Working with Data


SELECT 1 & 1;
Result:
1

Another and example:

SELECT 1 & 0;
Result:
0

“And”ing two integers is illustrated as follows:

decimal 3 = binary 011
decimal 5 = binary 101
3 AND 5
decimal 1 = binary 001

SELECT 3 & 5;
Result:
1

Boolean or
The boolean OR operator, the vertical pipe character (|), returns true if either input is true:

SELECT 1 | 1;
Result:
1

The following SELECT statement combines a set (true or 1) and a cleared (false or 0) bit
using the bitwise or operator:SELECT 1 | 0;

Result:
1
ORing two integers can be illustrated as follows:

decimal 3 = binary 011
decimal 5 = binary 101
3 OR 5
decimal 7 = binary 111

SELECT 3 | 5;
Result:
7

Boolean exclusive or
The exclusive or (XOR) bitwise operator, the carat ('), returns a value of true if either
input is true, but not if both are true. The operator is shown here:

c08.indd 180c08.indd 180 7/30/2012 4:21:13 PM7/30/2012 4:21:13 PM


http://www.it-ebooks.info
Free download pdf