<book>
<author>Bob Villa</author>
<author>Tom Whatever</author>
<author>Sarah kajdl</author>
</book>
我将如何查询任何有 Tom 的作者的记录?我见过的大多数查询示例都引用了值 [x],但我想搜索所有作者。
DECLARE @author as varchar(100)
SET @author = 'Tom Whatever'
SELECT xmlfield.value('/book/author')
WHERE xmlfield.value('/book/author') = @author
最佳答案
这是答案
DECLARE @x XML
SET @x = '<book>
<author>Bob Villa</author>
<author>Tom Whatever</author>
<author>Sarah kajdl</author>
</book>'
DECLARE @author AS VARCHAR(100)
SET @author = 'Tom Whatever'
SELECT c.value('.' ,'VARCHAR(100)')
FROM @x.nodes('book/author') AS t(c)
WHERE c.value('.' ,'VARCHAR(8000)') = @author
关于sql-server - 查询多个 XML 值,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/9891523/