Bitwise – SQL Server Syntax Example: Bitwise – T-SQL Example
Get 5 Hours of FREE PREMIUM Videos:
LearnVisualStudio.NET Free Preview
“ I am a lifetime member of LearnVisualStudio.net and a Premium Plus member of dotNetVideos.net.
LearnVisualStudio.net is awesome because it grows in value each year as more videos are added.
dotNetVideos.net is also great because it focuses a lot on MS Certifications and practical interview questions.
”
- Wade Harvey (IdealProgrammer.com)
Premium (Not Free) Video Tutorials
Free Video Tutorials & Free Tools
Bitwise – SQL Server Syntax Example: Bitwise – T-SQL Example
Purpose: – Illustrates the SQL Server syntax for the Bitwise operator .
Syntax:
operand1 bitwiseoperator operand2
– You can and (&), or(|), exclusively or (^) bits between two columns. The operands for bitwise operators can be any one of the data types of the integer or binary string data type categories (except for the image data type), except that both operands cannot be any one of the data types of the binary string data type category.
| Operator | Meaning |
|---|---|
| & (Bitwise AND) | Bitwise AND (two operands). |
| | (Bitwise OR) | Bitwise OR (two operands). |
| ^ (Bitwise Exclusive OR) | Bitwise exclusive OR (two operands). |
| T-SQL | | copy code | | ? |
-- Bitwise example from http://idealprogrammer.com |
-- PURPOSE: You can and (&), or(|), exclusively or (^) bits between two columns |
-- The operands for bitwise operators can be any one of the data types |
-- of the integer or binary string data type categories (except for the |
-- image data type), except that both operands cannot be any one of the |
-- data types of the binary string data type category. |
-- Here is a table of available combinations: |
--Left operand Right operand |
--binary int, smallint, or tinyint |
--bit int, smallint, tinyint, or bit |
--int int, smallint, tinyint, binary, or varbinary |
--smallint int, smallint, tinyint, binary, or varbinary |
--tinyint int, smallint, tinyint, binary, or varbinary |
--varbinary int, smallint, or tinyint |
-- SYNTAX: |
-- Operator Meaning |
-- & (Bitwise AND) Bitwise AND (two operands). |
-- | (Bitwise OR) Bitwise OR (two operands). |
-- ^ (Bitwise Exclusive OR) Bitwise exclusive OR (two operands). |
-- |
CREATE TABLE bitwise |
( |
a_int_value int NOT NULL, |
b_int_value int NOT NULL |
); |
GO |
INSERT bitwise VALUES (1, 2); |
GO |
-- (A | B) |
-- 0000 0000 0000 0001 = 1 |
-- 0000 0000 0000 0010 = 2 |
-- ------------------- |
-- 0000 0000 0000 0011 = 3 |
SELECT a_int_value | b_int_value AS 'Result of or-ing 1 & 2' |
FROM bitwise; |
GO |
DROP TABLE bitwise; |
GO |
Sample Output for Bitwise Example
Related posts:
- SQL Server / T-SQL Examples Here is a library of SQL Server / T-SQL Examples....
- BETWEEN AND – SQL Server Syntax Example: BETWEEN AND – T-SQL Example BETWEEN AND - SQL Server Syntax Example: BETWEEN AND -...
- SELECT AND SQL Server Syntax Example: SELECT AND logical operator T-SQL Example SELECT AND SQL Server Syntax Example: SELECT AND logical operator...
- SQL Server 2005 Express Tutorial: (13 Videos) Database mirroring, backup sql server 2005, sql server 2005 replication, sql server standard edition, download sql server 2005, compare sql server, sql server instance Excellent SQL Server 2005 Express series of 13 free videos...
- SELECT ALL SQL Server Syntax Example: SELECT ALL argument T-SQL Example SELECT ALL SQL Server Example: SELECT ALL argument T-SQL Example...
Related posts brought to you by Yet Another Related Posts Plugin.














































Comments
One Response to “Bitwise – SQL Server Syntax Example: Bitwise – T-SQL Example”Trackbacks
Check out what others are saying about this post...[...] SoonComing SoonComing SoonComing SoonComing SoonComing SoonComing SoonSelectAllAsBetween AndBitwiseCaseColumn AliasCompare DateComing SoonComing SoonComing SoonComing SoonComing SoonComing SoonComing [...]