By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
CREATE TABLE DBTable (DocXml xml);
INSERT DBTable VALUES ('<a>
<b>111</b>
<c>AAA</c>
<b>222</b>
<c>BBB</c>
<b>333</b>
<c>CCC</c>
</a>')
1 rows affected
SELECT
x1.a.value('let $b := b[text() = "111"][1] return (*[. >> $b]/text())[1]','varchar(100)')
FROM DBTable t
CROSS APPLY t.DocXml.nodes('/a') x1(a);
(No column name) |
---|
AAA |