【发布时间】:2012-02-02 03:06:39
【问题描述】:
我对 XQUERY/XPATH 非常陌生 :) 所以我很可能会以错误的方式解决这个问题。我有一个客户对象以下列格式序列化并存储在数据库列中。
<Customer xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Addresses>
<AddressBlock>
<AddressLine1>1234 SomeStreet Ave.</AddressLine1>
<City>SomeCity</City>
<State>SomeState</State>
<Zipcode>SomeZip</Zipcode>
</AddressBlock>
<AddressBlock>
<AddressLine1>5678 SomeOtherStreet Ave.</AddressLine1>
<City>SomeOtherCity</City>
<State>SomeOtherState</State>
<Zipcode>SomeOtherZip</Zipcode>
</AddressBlock>
</Addresses>
</Customer>
如果同一地址块中的 addressline1 和 city 包含某些关键字,我正在寻找一种方法来选择此记录。我有以下声明几乎可以满足我的要求。
select *
from users
where [UserData].exist('/Customer/Addresses/AddressBlock/AddressLine1/text()[contains(upper-case(.),""SOMESTREET"")]')=1
and [UserData].exist('/Customer/Addresses/AddressBlock/City/text()[contains(upper-case(.),""SOMECITY"")]')=1"
我唯一的问题是,如果第一个地址块包含 addressline1 而第二个地址块包含城市,则此语句也会返回记录。
【问题讨论】: