use recursive CTE to loop over chars

1

Please login or register to vote for this query.

(click on this box to dismiss)

Stack Overflow

Q&A for professional and enthusiast programmers

;with split(p,txt, ch, lft) as
(
select 1, substring(text,1,len(text)), left(text,1), ascii(left(text,1))
from comments
where id = 3059554
union all
select p + 1 , substring(txt, 2, len(txt)) , left(substring(txt, 2, len(txt)-1),1), ascii(substring(txt, 2, len(txt)-1))
from split
where len(txt)>1
)

select p, ch, lft
from split
OPTION (maxrecursion 600);

Enter Parameters

Options:
Switch to meta site
loading Hold tight while we fetch your results