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

Suddivisione di valori separati da virgola in colonne in più righe in SQL Server

SELECT col1,
       col2,
       Split.a.value('.', 'VARCHAR(100)') col3
FROM   (SELECT col1,
               col2,
               Cast ('<M>' + Replace(col3, ' ', '</M><M>') + '</M>' AS XML) AS Data
        FROM   [table]) AS A
       CROSS APPLY Data.nodes ('/M') AS Split(a)