Skip to content
Advertisement

SQL get value from XML in tag, by tag value

I have the following XML:

What I want is to get the value of the <value> tag in SQL.

Basically want to say get <value> where <Name> has the value of TEST1, as an example

This is what I have at the moment, but this depends on the position of the XML tag:

Advertisement

Answer

The best way to do this is not to put extra where .value clauses, but to do it directly in XQuery.

Use [nodename] to filter by a child node, you can even nest such predicates. text() gets you the inner text of the node:

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement