SqlServer教程

sqlserver解析xml

本文主要是介绍sqlserver解析xml,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
declare @XmlInput xml;
set @XmlInput='
<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>
    <note>
        <to>tom</to>
        <from>cat</from>
        <heading>test</heading>
        <body>test 123</body>
    </note>
    <note>
        <to>tom</to>
        <from>cat</from>
        <heading>test</heading>
        <body>test 123</body>
    </note>
</root>';
SELECT  R.D.value(N'(to)[1]','NVARCHAR(MAX)') AS tos,
        R.D.value(N'(from)[1]','NVARCHAR(MAX)') AS froms,
        R.D.value(N'(heading)[1]','NVARCHAR(MAX)') AS headings,
        R.D.value(N'(body)[1]','NVARCHAR(MAX)') AS bodys
FROM @XmlInput.nodes('/root/note') AS R(D)

结果:

 

这篇关于sqlserver解析xml的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!