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

Dividir uma linha com base em um valor de coluna


Farei isso usando XML
SELECT col1,
       Split.a.value('.', 'VARCHAR(100)') col2
FROM   (SELECT col1,
               col2,
               Cast ('<M>' + Replace(col2, ' ', '</M><M>') + '</M>' AS XML) AS Data
        FROM   Yourtable) AS A
       CROSS APPLY Data.nodes ('/M') AS Split(a) 

SQLFIDDLE DEMO