Using cte and Apply:
Declare @s nvarchar(9) = '223456789' ;with cte as( select n from (values(1),(2),(3),(4),(5),(6),(7),(8),(9)) as t(n)) select * from cte cross apply(select substring(@s, cte.n, 1) as c) ca
Output:
nc 1 2 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9
Or you can do this with table tables:
declare @s varchar(100) = '223456789' ;with t as(select row_number() over(order by (select null)) rn from (values(1),(1),(1),(1),(1),(1),(1),(1),(1),(1)) t1(n) cross join (values(1),(1),(1),(1),(1),(1),(1),(1),(1),(1)) t2(n)) select substring(@s, rn, 1) from t where rn <= len(@s)
Fiddle http://sqlfiddle.com/#!3/9eecb7db59d16c80417c72d1/570
source share