sql >> Base de Datos >  >> RDS >> Sqlserver

Dividir una fila en función de un valor de columna

Haré esto 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) 

DEMOSTRACIÓN DE SQLFIDDLE