1
declare @xmlVal xml
set @xmlVal = 
'<user>
    <token><id>ABC123</id><endDate>2013-06-16 18:48:50.111</endDate></token>
    <token><id>XYX456</id><endDate>2014-01-01 18:48:50.111</endDate></token>
</user>'

我需要整个令牌节点作为 id=ABC123 的 xml,所以输出将是:

<token>
    <id>ABC123</id>
    <endDate>2013-06-16 18:48:50.111</endDate>
</token>
4

2 回答 2

2
select @xmlVal.query('/user/token[id="ABC123"]')
于 2011-05-31T17:16:59.580 回答
1
SELECT  
a.b.value('id[1]','nvarchar(max)') id,
a.b.value('endDate[1]','datetime') endDate
 FROM    @xmlval.nodes('//user/token[id="ABC123"]') a(b)
 FOR XML PATH('token')
于 2011-05-31T11:54:03.970 回答