Retrieving multiple xml child node values

后端 未结 1 717
野性不改
野性不改 2021-01-23 22:51

I have a column of type varchar(max) populated with xml nodes and values; as an example, the column data starts with value1

相关标签:
1条回答
  • 2021-01-23 23:26

    Cast the column to XML (or change it in the table to XML) and shred the xml on //* to get all nodes in a table. Then you can use for xml path to concat the values back together.

    select (
           select ' '+X.N.value('text()[1]', 'varchar(max)')
           from (select cast(T.XMLCol as xml)) as T1(XMLCol)
             cross apply T1.XMLCol.nodes('//*') as X(N)
           for xml path(''), type
           ).value('substring(text()[1], 2)', 'varchar(max)')
    from T
    

    SQL Fiddle

    0 讨论(0)
提交回复
热议问题