SQL Server — how to shred one multielement XML to single-element XML values inserted into table?

梦想的初衷 提交于 2019-12-02 01:50:27

OK - so you have an XML variable that contains that XML you posted - and you need to shred this into its own individual bits?

Try something like this:

SELECT
    value_a = c.value('(@a)[1]', 'int'),
    value_b = c.value('(@b)[1]', 'int'),
    value_c = c.value('(@c)[1]', 'int') 
FROM @x.nodes('/row') AS T(c)

That gives me an output of :

Is that what you're looking for?

Update: ok, if I understand you correctly, this is what you want:

SELECT
    c.query('.')
FROM @x.nodes('/row') AS T(c)

Output:

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!