Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XQuery/XPath uses sql parameter?

I am try to implement the following code.

declare @para varchar(10) = 'b';
declare @x xml = '
<x>
    <a>1111</a>
    <b>2222</b>
    <c>3333</c>
</x>';
select @x.query('/x/sql:variable("@para")');

The above code should get the node of <b>2222</b>. However, it get the following error

Msg 9335, Level 16, State 1, Line 8
XQuery [query()]: The XQuery syntax '/function()' is not supported.
like image 764
ca9163d9 Avatar asked Mar 13 '12 17:03

ca9163d9


1 Answers

declare @para varchar(10) = 'b';
declare @x xml = '
<x>
    <a>1111</a>
    <b>2222</b>
    <c>3333</c>
</x>';
select @x.query('/x/*[local-name()=sql:variable("@para")]');
like image 147
Mikael Eriksson Avatar answered Sep 29 '22 08:09

Mikael Eriksson