Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
I'm working on a warehousing project retrieving data from a shrink-wrap solution. A couple of tables in the database have fields that store bit masks of 16 bits in an integer field to represent 16 boolean expressions. I need to migrate these tables to star based schemas, effectively splitting the 16bit field to 16 1 bit fields.As an example using a 4 bit integer:Bit 0 (0x01) = tiredBit 1 (0x02) = morally bankruptBit 2 (0x04) = happy to be herebit 3 (0x08) = wishing the bad man would to awayand an integer of 13, how do I returnTired Morally_Bankrupt Happy_to_be_here Go_Away_Bad_Man ----- ---------------- ---------------- ---------------1 0 1 1Edited by - rharmon on 11/12/2002 15:10:05
Arnold Fribble
Yak-finder General
1961 Posts
Posted - 2002-11-12 : 15:31:10
Something like this:
SELECT CAST(SIGN(bitmask & 0x01) AS bit) AS "tired", CAST(SIGN(bitmask & 0x02) AS bit) AS "morally bankrupt", CAST(SIGN(bitmask & 0x04) AS bit) AS "happy to be here", CAST(SIGN(bitmask & 0x08) AS bit) AS "wishing the bad man would to away"FROM (SELECT 13 AS bitmask) a