1
我对XQUERY/XPATH非常陌生:)所以我很可能会以错误的方式解决这个问题。我有一个客户对象序列化并以以下格式存储在数据库列中。使用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和同一个地址栏中的城市包含某些关键字。我有以下声明几乎做我正在寻找。
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"
我唯一的问题是这样的statment也将返回记录,如果第一addressblock包含addressline1和第二addressblock包含城市。
这是用于SQL Server吗? – 2012-01-04 07:04:36