Reputation: 3779
I was wondering if you can do bitwise operations on an int/uint fields in SQL SERVER?
Upvotes: 0
Views: 3145
Reputation: 36027
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
Upvotes: 3
Reputation: 146469
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...
Upvotes: 0
Reputation: 41357
Yes, you can, at least in Transact-SQL. See Microsoft's SQL Server documentation.
Upvotes: 0
Reputation: 4546
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.
Upvotes: -2