Actutal table ::
| Step_Configuration_Id | step_modes |
| 1 | ,7202, |
| 2 | ,7202,7204,7201,7203,7200, |
| 3 | ,7202, |
| 5 | ,7201,7203,7200, |
| 6 | ,7202,7201,7203,7200, |
Excepted output::
| Step_Configuration_Id | step_nodes |
| 1 | 7202 |
| 2 | 7204 |
| 2 | 7200 |
| 2 | 7202 |
| 2 | 7201 |
| 2 | 7203 |
| 3 | 7202 |
| 5 | 7201 |
| 5 | 7200 |
| 5 | 7203 |
| 6 | 7202 |
| 6 | 7200 |
| 6 | 7201 |
| 6 | 7203 |
Solution:
select
distinct Step_Configuration_Id,i.value('.', 'VARCHAR(20)') AS step_modes
from
(select Step_Configuration_Id,step_modes ,CAST('<i>'+ replace(step_modes,',','</i><i>')
+
'</i>' AS XML) AS step_modesXml from Step_Configurations
)
a CROSS APPLY step_modesXml.nodes('i') x(i) where i.value('.', 'VARCHAR(20)') <> ''
order by 1
No comments:
Post a Comment