好贷网好贷款

求解析一个xml 100interfaces_file]

发布时间:2016-12-3 21:56:01 编辑:www.fx114.net 分享查询网我要评论
本篇文章主要介绍了"求解析一个xml 100interfaces_file]",主要涉及到求解析一个xml 100interfaces_file]方面的内容,对于求解析一个xml 100interfaces_file]感兴趣的同学可以参考一下。

DECLARE @DocHandle int  declare @x as xml set @x='<customers> <employee emp="7725342193"> <name>William</name> </employee> <customer cust="256-5879"> <id>1</id> <info> <name>William</name> <desc>dev</desc> </info> <numbers> <home>152-456-5632</home> <mobile>158-896-7547</mobile> <fax>854-569-4726</fax> </numbers> </customer> <customer cust="256-5880"> <id>2</id> <info> <name>Patricio</name> <desc>enf</desc> </info> <numbers> <home>589-573-3516</home> <mobile>358-972-1597</mobile> <fax></fax> </numbers> </customer> <customer cust="256-6057"> <id>3</id> <info> <name>pedro</name> <desc>worker</desc> </info> <numbers> <home>582-647-5297</home> <mobile>325-125-4568</mobile> <fax>879-698-4785</fax> </numbers> </customer> </customers>' 结果 id customerID Customer Name desc Home Number employee name employee id 1 256-5879 William dev 152-456-5632 William 7725342193

怎么没有人回答呢?都睡了吗? 就是解析 <employee emp="7725342193"> <name>William</name> </employee> 以及customer 部分 然后求出name 和<info><name> 里面name值相等的

参考:http://www.cnblogs.com/MR_ke/archive/2010/08/23/1806460.html

DECLARE @DocHandle int  declare @x as xml set @x='<customers><employee emp="7725342193"><name>William</name></employee><customer cust="256-5879"><id>1</id><info><name>William</name><desc>dev</desc></info><numbers><home>152-456-5632</home><mobile>158-896-7547</mobile><fax>854-569-4726</fax></numbers></customer><customer cust="256-5880"><id>2</id><info><name>Patricio</name><desc>enf</desc></info><numbers><home>589-573-3516</home><mobile>358-972-1597</mobile><fax /></numbers></customer><customer cust="256-6057"><id>3</id><info><name>pedro</name><desc>worker</desc></info><numbers><home>582-647-5297</home><mobile>325-125-4568</mobile><fax>879-698-4785</fax></numbers></customer></customers>' select * from ( select col.value([email protected][1]','varchar(10)') as customerID, col.value('(info/name)[1]','varchar(50)') as  [Customer Name], col.value('(info/desc)[1]','varchar(50)') as [desc], col.value('(numbers/home)[1]','varchar(50)') as [Home Number] from @x.nodes('/customers/customer')T(col) ) a join ( select col.value([email protected][1]','varchar(10)') as [employee id], col.value('(name)[1]','varchar(50)') as  [employee name] from @x.nodes('/customers/employee')T(col) ) b on a.[Customer Name]=b.[employee name] /* customerID Customer Name desc Home Number employee id employee name 256-5879 William dev 152-456-5632 7725342193 William */

引用 3 楼  的回复:SQL code DECLARE @DocHandle int  declare @x as xml set @x='<customers><employee emp="7725342193"><name>William</name></employee><customer cust="256-5879"><id>1</id><info><name>William</name><desc>de…… 3q,good 

上一篇:sqlserver 按月份统计 出金、入金、剩余金额 20hubowei7]
下一篇:SQL2005 数据库引擎优化顾问无法打开新连接 40分,无满意结帖,结帖人ERPSURE]

相关文章

相关评论