I need advice on how to handle relatively large set of flags in my SQL2k8 table.
Two question, bear with me please :)
Let's say I have 20 flags I'd like to store for one record.
For example:
CanRead = 0x1 CanWrite = 0x2 CanModify = 0x4 ... and so on to the final flag 2^20
Now, if i set the following combination of one record: Permissions = CanRead | CanWrite
I can easily check whether that record has required permission by doing WHERE (Permissions & CanRead) = CanRead
That works.
But, I would also like to retrieve all records that can either write OR modify.
If I issue WHERE (Permissions & ( CanWrite | CanModify )) = (CanWrite | CanModify) i obviously won't get my record that has permissions set to CanRead | CanWrite
In other words, how can I find records that match ANY of the flags in my mask that i'm sending to the procedure?
Second question, how performant is in in SQL 2008? Would it actually be better to create 20 bit fields?
Thanks for your help