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

Converter o valor da coluna separada por vírgulas em linhas


tente isso
 SELECT A.[id],  
     Split.a.value('.', 'VARCHAR(100)') AS String  
 FROM  (SELECT [id],  
         CAST ('<M>' + REPLACE([string], ',', '</M><M>') + '</M>' AS XML) AS String  
     FROM  TableA) AS A CROSS APPLY String.nodes ('/M') AS Split(a); 

consulte aqui

http://www.sqljason.com/2010/05/converting-single-comma-separated-row.html