在下面的代码块中,我可以查询到 DataElements。对于以下 xml
DECLARE @xmlString XML;
SELECT @xmlString='<Activity xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<ActivityCode>570</ActivityCode>
<ActivityId>0011d966-fa28-440c-9196-5dbe3c40b2ac</ActivityId>
<CreateDateTime>2014-06-19T06:57:46.9854126-04:00</CreateDateTime>
<DataElements xmlns:a="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<a:KeyValueOfstringDataElementLjh4bohd>
<a:Key>AgentId</a:Key>
<a:Value>
<DataType>String</DataType>
<Name>AgentId</Name>
<Value>abc\xyxaa</Value>
</a:Value>
</a:KeyValueOfstringDataElementLjh4bohd>
<a:KeyValueOfstringDataElementLjh4bohd>
<a:Key>PhoneCallStartTime</a:Key>
<a:Value>
<DataType>String</DataType>
<Name>PhoneCallStartTime</Name>
<Value>06/19/2014 10:57:47</Value>
</a:Value>
</a:KeyValueOfstringDataElementLjh4bohd>
</DataElements>
</Activity
> 在 XQery 下方
SELECT @xmlString.query('for $activity in /Activity
let $activityId := $activity/DataElements
return data($activityId)
') AS [activityId]
GO
正在给我结果:
AgentIdStringAgentIdabc\xyxaaPhoneCallStartTimeStringPhoneCallStartTime06/19/2014 10:57:47
但我想要的是,如果我通过 AgentId,我应该得到 abc\xyxaa,如果我通过 PhoneCallStartTime,我应该得到 06/19/2014 10:57:47。请帮忙