• Easy enough using Jeff Moden's famous DelimitedSplit8K function:

    WITH SampleData (s) AS

    (

    SELECT '2;Andy;Andy''s way 2;24;Glue;3;35;39;Oyster;2;9'

    UNION ALL SELECT '3;Tom;Tom''s way 3;39;Oyster;2;9'

    ),

    SplitList AS

    (

    SELECT Item, ItemNumber=CASE WHEN ItemNumber <= 3 THEN 0 ELSE ItemNumber/4 END, s

    FROM SampleData

    CROSS APPLY dbo.DelimitedSplit8K(s, ';')

    )

    SELECT s2=STUFF(

    (

    SELECT ';' + Item

    FROM SplitList a

    WHERE a.s = b.s AND a.ItemNumber = b.ItemNumber

    FOR XML PATH('')

    ), 1, 1, '')

    FROM SplitList b

    GROUP BY s, ItemNumber;

    Find that function here: http://www.sqlservercentral.com/articles/Tally+Table/72993/ Tally Oh!


    My mantra: No loops! No CURSORs! No RBAR! Hoo-uh![/I]

    My thought question: Have you ever been told that your query runs too fast?

    My advice:
    INDEXing a poor-performing query is like putting sugar on cat food. Yeah, it probably tastes better but are you sure you want to eat it?
    The path of least resistance can be a slippery slope. Take care that fixing your fixes of fixes doesn't snowball and end up costing you more than fixing the root cause would have in the first place.

    Need to UNPIVOT? Why not CROSS APPLY VALUES instead?[/url]
    Since random numbers are too important to be left to chance, let's generate some![/url]
    Learn to understand recursive CTEs by example.[/url]
    [url url=http://www.sqlservercentral.com/articles/St