Erin i have this saved in my snippets, that will get you 90% there;
this is enumerating the bits as to wether they are true or false.
;WITH myStrings (val)
AS (
SELECT '00001001001' UNION ALL
SELECT '10101' UNION ALL
SELECT '1010100' UNION ALL
SELECT '010111111' )
,
FormattedStrings AS (
SELECT right('0000000000000000000000000000000' + val ,31) As sval
FROM myStrings),
MiniTally AS (
SELECT TOP 31 row_number() OVER (order by name) As N from sys.columns order by name )
select
sval,
MiniTally.N,
CONVERT(int,SUBSTRING(REVERSE(sval),MiniTally.N,1)) As bval,
POWER(2,N-1) As thePower,
CASE
WHEN (CONVERT(int,SUBSTRING(REVERSE(sval),MiniTally.N,1)) & 1) = 0
THEN 'False'
ELSE 'True'
END As [True?]
FROM FormattedStrings
CROSS JOIN MiniTally
order by sval,MiniTally.N
from there, if you filtered it for only true, and used FOR XML to concatenate the [thePower] column, you'd have what you were asking for.
does that help?
i can look at making the concat work if you are a bit weak on that too.
Lowell