• You're right, my suggestion doesn't perform well.

    It could be done better - here is a slightly improved version

    ;with spc (id, val, num, k) as (

    select a.id, a.val, t.num, ROW_NUMBER() over (partition by a.id order by t.num) as k

    from @vTable a inner join tally t on t.num <= len(a.val)+2 and SUBSTRING(' '+a.val+' ',t.num,1) = ' '

    )

    select a.id, substring(a.Val, a.num, b.num- 1 - a.num) from spc a inner join spc b on b.id = a.id and b.k = a.k+1

    My aversion to recursive CTEs may well be unjustified, it's just that you do need to understand and allow for the likely recursion depth when developing them.

    However, you also need to be careful when writing any SQL, as the poor performance of my iterative code demonstrates excellently!