求助 XML查询

最爱午夜 2014-05-22 04:56:35
表中有一个字段A,数据类型是XML。
<EBPCaseDetailType>
<openReason xmlns="http://www.ebay.com/marketplace/resolution/v1/services">Item not received</openReason>
<decision xmlns="http://www.ebay.com/marketplace/resolution/v1/services">OTHER</decision>
<FVFCredited xmlns="http://www.ebay.com/marketplace/resolution/v1/services">false</FVFCredited>
<globalId xmlns="http://www.ebay.com/marketplace/resolution/v1/services">EBAY_UK</globalId>
<responseHistory xmlns="http://www.ebay.com/marketplace/resolution/v1/services">
<author>
<role>BUYER</role>
</author>
<activity>contactCustomerSupport</activity>
<creationDate>2013-07-02T10:13:48Z</creationDate>
</responseHistory>
<responseHistory xmlns="http://www.ebay.com/marketplace/resolution/v1/services">
<author>
<role>EBAY</role>
</author>
<activity>systemExpireGrace</activity>
<creationDate>2013-06-30T16:00:54Z</creationDate>
</responseHistory>
<responseHistory xmlns="http://www.ebay.com/marketplace/resolution/v1/services">
<note>i have not recived the item yet</note>
<author>
<role>BUYER</role>
</author>
<activity>create</activity>
<creationDate>2013-06-23T01:26:25Z</creationDate>
</responseHistory>
<agreedRefundAmount xmlns="http://www.ebay.com/marketplace/resolution/v1/services">0</agreedRefundAmount>
<detailStatus xmlns="http://www.ebay.com/marketplace/resolution/v1/services">3</detailStatus>
<initialBuyerExpectation xmlns="http://www.ebay.com/marketplace/resolution/v1/services">103</initialBuyerExpectation>
</EBPCaseDetailType>
我想找到字段A中是否存在节点 <activity>systemExpireGrace</activity>
代码如下:
select * from tableName
where A.exits('/EBPCaseDetailType/responseHistory/activity')>0
结果发现没有找到一条数据,实际上有很多条数据满足条件。
请教,这是什么问题,给出代码,谢谢!!
...全文
162 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
唐诗三百首 2014-05-23
  • 打赏
  • 举报
回复

create table tj(id int,字段A xml)

insert into tj(id,字段A)
select 101,
'<EBPCaseDetailType>
  <openReason xmlns="http://www.ebay.com/marketplace/resolution/v1/services">Item not received</openReason>
  <decision xmlns="http://www.ebay.com/marketplace/resolution/v1/services">OTHER</decision>
  <FVFCredited xmlns="http://www.ebay.com/marketplace/resolution/v1/services">false</FVFCredited>
  <globalId xmlns="http://www.ebay.com/marketplace/resolution/v1/services">EBAY_UK</globalId>
  <responseHistory xmlns="http://www.ebay.com/marketplace/resolution/v1/services">
    <author>
      <role>BUYER</role>
    </author>
    <activity>contactCustomerSupport</activity>
    <creationDate>2013-07-02T10:13:48Z</creationDate>
  </responseHistory>
  <responseHistory xmlns="http://www.ebay.com/marketplace/resolution/v1/services">
    <author>
      <role>EBAY</role>
    </author>
    <activity>systemExpireGrace</activity>
    <creationDate>2013-06-30T16:00:54Z</creationDate>
  </responseHistory>
  <responseHistory xmlns="http://www.ebay.com/marketplace/resolution/v1/services">
    <note>i have not recived the item yet</note>
    <author>
      <role>BUYER</role>
    </author>
    <activity>create</activity>
    <creationDate>2013-06-23T01:26:25Z</creationDate>
  </responseHistory>
  <agreedRefundAmount xmlns="http://www.ebay.com/marketplace/resolution/v1/services">0</agreedRefundAmount>
  <detailStatus xmlns="http://www.ebay.com/marketplace/resolution/v1/services">3</detailStatus>
  <initialBuyerExpectation xmlns="http://www.ebay.com/marketplace/resolution/v1/services">103</initialBuyerExpectation>
</EBPCaseDetailType>'


-- 查询存在的节点 <activity>contactCustomerSupport</activity>
select * 
 from tj 
 where 字段A.exist('
 declare namespace NS="http://www.ebay.com/marketplace/resolution/v1/services";
 /EBPCaseDetailType/NS:responseHistory/NS:activity[.="contactCustomerSupport"]')=1

/*
id          字段A
----------- ----------------------------------------
101         <EBPCaseDetailType><openReason ......

(1 row(s) affected)
*/


-- 查询存在的节点 <activity>create</activity>
select * 
 from tj 
 where 字段A.exist('
 declare namespace NS="http://www.ebay.com/marketplace/resolution/v1/services";
 /EBPCaseDetailType/NS:responseHistory/NS:activity[.="create"]')=1

/*
id          字段A
----------- ----------------------------------------
101         <EBPCaseDetailType><openReason ......

(1 row(s) affected)
*/


-- 查询不存在的节点 <activity>1122334</activity>
select * 
 from tj 
 where 字段A.exist('
 declare namespace NS="http://www.ebay.com/marketplace/resolution/v1/services";
 /EBPCaseDetailType/NS:responseHistory/NS:activity[.="1122334"]')=1

/*
id          字段A
----------- ---------------

(0 row(s) affected)
*/
最爱午夜 2014-05-23
  • 打赏
  • 举报
回复
没有写错,就是这样,但是查不出数据。
exception92 2014-05-22
  • 打赏
  • 举报
回复
A.exits('/EBPCaseDetailType/responseHistory/activity')>0 条件是不是写错了??

34,593

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧