SQL Server Error: XQuery [nodes()]: A node or set of nodes is required for 'nodes()'

拜拜、爱过 提交于 2020-06-17 11:37:36

问题


I was trying to pass my variables into the nodes() and value() methods, but some errors occurred:

DECLARE @path VARCHAR(50) = '/A/B/C',
        @node VARCHAR(20) = '@name',
        @result XML ='
        <A>
            <B>
                <C name='nameA'/>
            </B>
            <B>
                <C name='nameB'/>
            </B>
        </A>
        ' 

SELECT T.c.value('./sql:variable("@node")', 'varchar(50)')
FROM @result.nodes('sql:variable("@path")') T(c)

Raises the error:

XQuery [nodes()]: A node or set of nodes is required for 'nodes()'

Also, when I use '/A/B/C' to replace @path, the error raised:

XQuery [value()]: The XQuery syntax '/function()' is not supported.

My goal is to get a table like:

|Name|
|NameA|
|NameB|
|···|

来源:https://stackoverflow.com/questions/62401972/sql-server-error-xquery-nodes-a-node-or-set-of-nodes-is-required-for-node

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!