• ok this got interesting so i did the whole thing.

    enjoy!

    /*

    valSkills

    000010010011,8,64

    0101111111,2,4,8,16,32,128

    101011,4,16

    10101004,16,64

    */

    ;WITH myStrings (val)

    AS (

    SELECT '00001001001' UNION ALL

    SELECT '10101' UNION ALL

    SELECT '1010100' UNION ALL

    SELECT '010111111' )

    ,

    FormattedStrings AS (

    SELECT val,

    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 ),

    StagedData

    AS

    (

    select

    val,

    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

    )

    SELECT val,stuff(( SELECT ',' + convert(varchar,ThePower)

    FROM StagedData s2

    WHERE s2.val= s1.val --- must match GROUP BY below

    And [True?]='True'

    ORDER BY N

    FOR XML PATH('')

    ),1,1,'') as [Skills]

    FROM StagedData s1

    GROUP BY s1.val --- without GROUP BY multiple rows are returned

    ORDER BY s1.val

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!