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