【4.41】sql server如何把xml转换成表格数据?

假装没事ソ 提交于 2020-04-18 18:08:20

 

declare @temp xml;
set @temp='<root><note>
<to>George</to>
<from>John</from>
<heading>Reminder</heading>
<body>Dont forget the meeting!</body>
</note>
<note>
<to>tom</to>
<from>cat</from>
<heading>test</heading>
<body>test 123</body>
</note>
</root>';
select [to]=o.value('to[1]','nvarchar(500)'),
               [from]=o.value('from[1]','nvarchar(500)'),
               [heading]=o.value('heading[1]','nvarchar(500)'),
               [body]=o.value('body[1]','nvarchar(500)')               
             from (select x=@temp) a
             cross apply x.nodes('root/note') x(o)

  

 

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