问题
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