I'm storing addresses in an XML address column, and I need to be able
to do partial searches...
For example...
declare @.tAddress table (Address xml DEFAULT '<Address Record />' )
INSERT INTO @.tAddress (Address)
VALUES ('<AddressType name="Shipping">
<AddressRecord StreetLine1="111 Main"
City="Houston"
State="TX"
ZipCode = "11111" />
</AddressType> ');
A single address could have multiple address types (billing and
shipping) and multiple entries for each one.
I know how to query for an exact match on a column...
SELECT Address FROM @.tAddress WHERE
Address.exist('/AddressType/AddressRecord[ @.City = "Houston" ]') =1
However...I'm getting errors when I try to use a contains (in the
same way I'd use a City Like '%ous%'
How would I code a contains on any particular column?
Thanks!
KevinFollow-up...
I tried the following:
SELECT * FROM @.tAddress
where
address.exist('/AddressType/AddressRecord/City/text()[contains(.,"Houston")]
')
= 1
It doesn't bomb, but it generates zero results.
I'm sure I'm missing something, but don't know what.
Kevin|||Try this
SELECT * FROM @.tAddress
where
address.exist('/AddressType/AddressRecord [contains(@.City,"Houston")]')
= 1|||On 10 Mar 2006 12:08:09 -0800, markc600@.hotmail.com wrote:
>Try this
>SELECT * FROM @.tAddress
>where
>address.exist('/AddressType/AddressRecord [contains(@.City,"Houston")]')
>= 1
THAT WORKED!!!!!
You're the man!!!!!!!!!!!
THANK YOU!!!!!!!
Kevin
Wednesday, March 7, 2012
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment