Sqlserver
 sql >> Base de Dados >  >> RDS >> Sqlserver

Dividir uma string em caracteres individuais no 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