我有一个包含xml列的表,其中包含以下数据。
<a:Tracking>
<b:TrackingID>343545</b:TrackingID>
<b:TrackingID n:id="abc">12345</b:TrackingID>
</a:Tracking>
我需要获取节点b:TrackingID的值,其中包含属性n:id,其值为“abc”。
我正在尝试以下代码而没有任何成功。有没有人有任何想法?谢谢!
WITH XMLNAMESPACES ('http://nm.gov/nm/2.0' as b,
'http://nm.gov/nm/structures/2.0' as n)
Select @TrackingID = Message.value('(//b:TrackingID)[@n:id = "abc"]', 'varchar(100)')
From tblData e WITH(NOLOCK)
Where ID = 12
答案 0 :(得分:0)
WITH XMLNAMESPACES ('http://nm.gov/nm/2.0' as b,
'http://nm.gov/nm/structures/2.0' as n)
Select @TrackingID = Message.value('(//b:TrackingID/@n:id[. = "abc"]', 'varchar(100)')
From tblData e WITH(NOLOCK)
Where ID = 12