Mega Code Archive

 
Categories / MSSQL Tutorial / Data Types
 

Selecting data using bitwise operators

Operator    Description      &           Bitwise, logical AND         ?           Bitwise, logical OR      ^           Bitwise, logical exclusive OR        ~           Bitwise NOT  4> 5> 6> 7>     CREATE TABLE tableX ( 8>         bitPriced BIT, 9>         bitCredit_checked BIT, 10>         bitAllocated BIT, 11>         bitShipped BIT 12>     ) 13>     GO 1> 2>     INSERT tableX (bitPriced, bitCredit_checked, bitAllocated, bitShipped) VALUES (1,1,0,0) 3>     INSERT tableX (bitPriced, bitCredit_checked, bitAllocated, bitShipped) VALUES (1,0,1,0) 4>     INSERT tableX (bitPriced, bitCredit_checked, bitAllocated, bitShipped) VALUES (0,0,0,0) 5>     INSERT tableX (bitPriced, bitCredit_checked, bitAllocated, bitShipped) VALUES (1,1,1,0) 6>     GO (1 rows affected) (1 rows affected) (1 rows affected) (1 rows affected) 1> 2>     SELECT * 3>     FROM tableX 4>     WHERE bitAllocated ^ bitPriced = 1 5>     GO bitPriced bitCredit_checked bitAllocated bitShipped --------- ----------------- ------------ ----------         1                 1            0          0 (1 rows affected) 1> 2>     DROP TABLE tableX 3>     GO 1> 2>