我已经在这个网站和互联网上进行了搜索,但似乎无法找到任何可以满足这个简单请求的东西。我只想显示与术语相关的单词,例如使用 TEST 下面的 xml 列将被提取。
xml列如下:
<A>
<resources id="1" resourceType="Template" term="TEST" version="1" />
</A>
我尝试使用以下命令,但它返回 NULL。
select
Res.value('(/A/term)[1]','nvarchar(50)') as 'Res'
from Con
where Res is not null
提前谢谢您。
最佳答案
试试这样
select
Res.value('(/A/resources/@term)[1]','nvarchar(50)') as 'Res'
from Con
where Res is not null
term
是元素 @
内的一个属性(需要 <resources>
符号)下面<A>
。您的 xpath 无法正确反射(reflect)这一点...
关于sql - 从 SQL XML 中提取字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49167864/