SQL 2005 XML Searching

SQL 2005 XML Searching

am 16.04.2008 07:11:38 von zzzxtreme

hi i have a table with an XML column

this XML data looks like this

>



could anyone help guide me on how to search something like this?

-------
Select * from Table Where (XMLColumn contains attribute of id="2" and
value like "y%")

Re: SQL 2005 XML Searching

am 16.04.2008 16:28:20 von Plamen Ratchev

Here is one way:

SELECT keycol, datacol
FROM Foo
WHERE datacol.exist('/details/attribute[@id = "2"]') = 1
AND datacol.exist('/details/attribute[substring(@value, 1, 1) = "y"]') =
1;

HTH,

Plamen Ratchev
http://www.SQLStudio.com