Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Querying Individual Binary Bit Fields

Author  Topic 

WebInspired
Starting Member

1 Post

Posted - 2012-07-16 : 07:51:55
In a SQL table I have a field declared as binary(16), which effectively I use to store a bit mask of settings for a web app.

In my actual web app (using .NET Entity Frameworks), I store a 1 or a 0 in specific positions to indicate if a permission is set or not

eg...

//Define BWAND Process bit positions
private const int pPAF = 1;
private const int pPING = 2;
private const int pDedup = 3;
private const int pProfanity = 4;
private const int pTelVerify = 5;


then set by my field - which is called ProcessBWAND - as follows, example

ProcessBWAND[pPING] = (byte)0 or (byte)1

this all works fine for storing the values etc so I may get an entry (from SQL Manager) like this.

0x00010101010100000000000000000000

Which means all the above bit flags have been set.

Anyway my question is, how from a SQL query can I test if any of the records for example have a specific bit set in the ProcessBWAND field?

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2012-07-16 : 09:20:34
Try using and (&) to check for bits
See
http://www.nigelrivett.net/SQLTriggers/Columns_updated.html

That gets the bits that are set.

==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -