• took me a bit for this one; this seems to do the whole shebang

    ;WITH

    TENS (N) AS (SELECT 0 UNION ALL SELECT 0 UNION ALL SELECT 0 UNION ALL

    SELECT 0 UNION ALL SELECT 0 UNION ALL SELECT 0 UNION ALL

    SELECT 0 UNION ALL SELECT 0 UNION ALL SELECT 0 UNION ALL SELECT 0),

    THOUSANDS (N) AS (SELECT 1 FROM TENS t1 CROSS JOIN TENS t2 CROSS JOIN TENS t3),

    TALLY (N) AS (SELECT ROW_NUMBER() OVER (ORDER BY (SELECT 0)) FROM THOUSANDS)

    ,

    MyCTE ([reference],[startdate],[pattern])

    AS (SELECT 'TestRef-AA',convert(datetime,'09/09/2013 10:45'),'1111111 1111111 111 111 111111 1111' )

    SELECT CASE WHEN SUBSTRING([pattern],N,1) = '1'

    THEN DATEADD(wk,Tally.N,[startdate])

    ELSE NULL

    END As CalcDate,*,

    SUBSTRING([pattern],N,1)

    FROM MyCTE

    CROSS JOIN Tally

    WHERE N <= LEN([pattern])

    --AND SUBSTRING([pattern],N,1) = '1'

    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!