1

In C# I use to check the boolean gates like this

bool isValid= 3 & 1;

i.e whether 1 is contained in 3 or not. It comes true. as 3 has both the numbers 1 and 2 . My series continues as 2 raise to the power of n i.e 1, 2, 4, 8, 16, 32, 64, 128.. I need to check the same logic in SQL i.e I will pass the total and I need to check whether x number lies in it or not.

Rocky Singh
  • 15,128
  • 29
  • 99
  • 146
  • 1
    3 & 1 really returns boolean? I do not believe. This is bitwise AND so should return numeric value, looks like you missed second symbol & because you mentioned boolean gates – sll Aug 17 '11 at 21:15
  • possible duplicate of [Comparing two bitmasks in SQL to see if any of the bits match](http://stackoverflow.com/q/143712/90527), [& operator in a SQL Server WHERE Clause](http://stackoverflow.com/q/670230/90527) – outis Mar 29 '12 at 00:41

1 Answers1

4

SQL Server also supports bitwise Operators:

http://msdn.microsoft.com/en-us/library/ms176122.aspx

Example:

DECLARE @isValid bit 
SET @isValid = 3 & 1
Code Magician
  • 23,217
  • 7
  • 60
  • 77