views:

1124

answers:

6

I was wondering if you can do bitwise operations on an int/uint fields in SQL SERVER?

A: 

Um.... it's a BIT what value would you like to store other than 0 or 1? So direct answer, no.

Edit. I answered your topic, not your description. Please clarify question.

WaldenL
+1  A: 

Bits contain 0 and 1, that's it.

Matt Grande
A: 

Sorta :-) but you are limited to only one bit so you only have 0 or 1 to work with

DJ
+3  A: 

Yes, you can do bitwise operations on int/uint fields.

For example, consider this:

declare @myvar int
set @myvar = 3
if ((@myvar & 2) = 2)
begin
   print 'hello'
end
eglasius
updated my answer, the syntax was way off - the concept is the same :)
eglasius
I'm sure the question has changed since you answered it (because your code example is correct), so for the sake of clarity, could you update your opening text to say, "Yes, you can do bitwise operations on int/uint fields"? I would do it myself, but I guess I don't have enough rep points.
David
@David that's right, the question changed after that answer - thx (updated).
eglasius
A: 

Yes, you can, at least in Transact-SQL. See Microsoft's SQL Server documentation.

Jen
A: 

The answer is YES !

Just because they're called bitwise operators, dopes not mean they only operate on data values stored in the SQL Server "Bit" typoe.

All data is stored in the computer as bits... so you can use the Bitwise operators on many types, including any integral types int, smallint, tinyint, etc..

the bitwise operators are not use-limited to Bit type values.

I don't know if you can use it on other types,, but just try it and see what happens...

Charles Bretana