使用SQL读取XML节点 [英] Read XML node using SQL

查看:91
本文介绍了使用SQL读取XML节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hi Team,



如何使用SQL读取XML节点?



我有以下XML -

Hi Team,

How to read XML node using SQL?

I have below XML -

"<sales>
  <sale>
	<name>Joy G</name>
	<details>TYOP 1,KODF 1243</details>
  </sale>
</sales> "



我需要从SQL查询返回节点详细信息之间的文本

输出为 - TYOP 1,KODF 1243



知道查询的内容



谢谢

RD Burmon



我尝试了什么:



SELECT @ List = ncvalue('DETAILS [1]','varchar(max)')

来自@Batches t

交叉应用RawXml.nodes('/')n(c)


and I need the text between node "details" in return from SQL query
Output would be - TYOP 1,KODF 1243

Any idea what the query would be

Thanks
RD Burmon

What I have tried:

SELECT @List= n.c.value('DETAILS[1]','varchar(max)')
FROM @Batches t
Cross Apply RawXml.nodes('/') n(c)

推荐答案

这应该这样做:

SELECT n.xmlData .value('(sales / sale / details)[1]','varchar(max)')

来自xmlTable

交叉应用xmlData.nodes('/' )n(xmlData)



以及您的表/字段名称:



SELECT n.RawXml。值( '(销售/销售/详情)[1]','v' archar(max)')

FROM批次

交叉应用RawXml.nodes('/')n(RawXml)
This should do it:
SELECT n.xmlData.value('(sales/sale/details)[1]','varchar(max)')
FROM xmlTable
Cross Apply xmlData.nodes('/') n(xmlData)

and with your table/field names:

SELECT n.RawXml.value('(sales/sale/details)[1]','varchar(max)')
FROM Batches
Cross Apply RawXml.nodes('/') n(RawXml)


这篇关于使用SQL读取XML节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆