SQL 2005 XML Searching

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • zzzxtreme@gmail.com

    SQL 2005 XML Searching

    hi i have a table with an XML column

    this XML data looks like this

    <details><attri bute id="1" value="x"/><attribute id="2" value="y"/
    ><attribute id="3" value="z"/></details>

    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%")
  • Plamen Ratchev

    #2
    Re: SQL 2005 XML Searching

    Here is one way:

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

    HTH,

    Plamen Ratchev


    Comment

    Working...