• Here's another option. I was thinking more of creating it for an iTVF (but leaving that part to you).

    DECLARE @String varchar(20) = '00001001001';

    WITH e1(N) AS(

    SELECT N FROM (VALUES(0),(0),(0),(0),(0),(0),(0),(0),(0),(0))e(N)

    ),

    cteTally(N) AS(

    SELECT TOP(LEN(@String)) ROW_NUMBER() OVER(ORDER BY(SELECT NULL)) - 1 FROM e1 a, e1 b

    )

    SELECT STUFF((SELECT ',' + CAST( POWER(2,N) AS varchar(5))

    FROM cteTally

    WHERE SUBSTRING( @String, LEN(@String) - N, 1) = 1

    ORDER BY N DESC

    FOR XML PATH('')), 1, 1, '')

    By the way, it was a surprise that ^ is not power in SQL and I had to use the POWER function instead. I haven't used it in a long, long time (if I ever used it before).

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2