• This looked like an extremely odd situation but a fun challenge. It can in fact be accomplished without loops. You have to combine a couple of techniques, both the delimited split and the quirky update.

    You need to read the article referenced in my signature about splitting strings. In there you will find the code for the DelimitedSplit8K function.

    Then you need to read this article about running totals. http://www.sqlservercentral.com/articles/T-SQL/68467/[/url]

    Why running totals? I use the running total to keep track of the length of the string at the time of each split.

    Make sure that you read and understand the concepts in both articles. These are pretty advanced topics and you are the one who has to support this code.

    declare @SomeString varchar(50) = '12345678910111213141516'

    declare @Pos varchar(50) = '1,1,2,5,4,2'

    --For the quirky update we need this data in a table of some sort.

    create table #StringOutput

    (

    RowNum int,

    ColLength int,

    SumOfLength int

    )

    insert #StringOutput

    select *, null --The null will be updated with the running total

    from dbo.DelimitedSplit8K(@pos, ',')

    declare @Total int = 0

    --this is the quirky update used to store the running total

    update #StringOutput

    set @Total = SumOfLength = @Total + ColLength

    OPTION (MAXDOP 1)

    --now that we know where in the original string and the length of each segment we just need to get the correct substring for each segment.

    select *, substring(@SomeString, SumOfLength - ColLength + 1, ColLength) as FinalOutput

    from #StringOutput

    drop table #StringOutput

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/