Filter SQL queries on the XML column using XPath/XQuery

后端 未结 1 1851
情歌与酒
情歌与酒 2021-02-04 13:24

I\'m having a table with one XML column. I\'d like to filter out the rows where a specific attribute in the XML match a string, essentially doing a WHERE or HAVING.

The

1条回答
  •  孤独总比滥情好
    2021-02-04 14:09

    Found it. Instead of using query() I should be using exist().

    My query would then be

    SELECT id, xml.query('data(/xml/info/@name)') as Value
    FROM Table1
    WHERE xml.exist('/xml/info/[@name=sql:variable("@match")]') = 1
    

    0 讨论(0)
提交回复
热议问题