I have a bitwise enum with FlagsAttribute set over it like this –
[FlagsAttribute]
public enum MyEnum
{
None = 0,
First = 1,
Second = 2,
Third = 4,
Five = 8,
Six = 16,
Seven = 32,
Eight = 64,
Nine = 128
}
Now, in C# i am storing this value in a property say MyProperty and on save i write this property in my SQL database in integer column. Suppose if i select First,Second,Five from code then in database it will be saved as '11'.
I know i can fetch value from DB and just need to typecast int value to MyEnum and it will give me the values. But, i want some manipulation to be done on SQL data in some Stored procedure where obviously i can’t typecast it to Enum value. So, is there a way out which can let me know about the individual values.
Like in example if 11 is stored, any way that i can get it as "1+2+8"
This may help to get you started:
Where
11is your stored value.This will return non-zero values for each value that is set (i.e.
Select 11 & 1 As 'First'returns1,Select 11 & 2 As 'Second'returns 2,Select 11 & 4 As 'Third'returns0and so on.