由于 SQL Server 不支持跟随兄弟轴 - 获得它的最佳方法是什么?假设我有这样的 XML,我想在匹配值 'dog' 的节点之后获取第一个 'b' 节点:
Since SQL Server does not support following-sibling axis - what is the best way to get it? Let's say I have XML like this and I would like to get the first 'b' node after a node matching the value 'dog':
<root>
<a>cat</a>
<b>Cats don't like milk</b>
<a>dog</a>
<b>Dogs like everything</b>
</root>
你可以尝试这样的事情.
You could try something like this.
declare @X xml = '
<root>
<a>cat</a>
<b>Cats don''t like milk</b>
<a>dog</a>
<c>not this</c>
<b>Dogs like everything</b>
<b>and not this</b>
</root>'
select @X.query('(/root/b[. >> (/root/a[. = "dog"])[1]])[1]')
这篇关于在 SQL Server XPath 中获取跟随兄弟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!