Sql-server – Using a 512 bit binary column as a bit field

bit manipulationbitwise-comparisonsql server

I'm designing a table to keep track of a value that has to represent the on-off setting of several hundred states. I would expand this to 512, to give room for future growth and be a power of two.

So I want a 64 byte = 512 bit column. My problem is that SqlServer bitwise operations don't support right operands larger than int, so there would be no way to access any bits past 32.

How can I handle this issue?

Best Answer

SQL Server supports up to 1,024 Columns per nonwide table. Use them. The bit data type, if declared as NOT NULL, will take one bit of storage. You can then address each state specifically by name, making for cleaner, more maintainable code.

Related Question