Sqlserver
 sql >> Database >  >> RDS >> Sqlserver

Dividi una stringa in singoli caratteri in Sql Server 2005

;with cte as
(
  select ID,
         substring(data, 1, 1) as Chars,
         stuff(data, 1, 1, '') as data,
         1 as RowID
  from @t
  union all
  select ID,
         substring(data, 1, 1) as Chars,
         stuff(data, 1, 1, '') as data,
         RowID + 1 as RowID
  from cte
  where len(data) > 0
)
select ID, RowID, Chars
from cte
order by ID, RowID