XQuery / XPath uses sql parameter?

I am trying 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 node from <b>2222</b> . However, it gets the following error:

  Msg 9335, Level 16, State 1, Line 8
 XQuery [query ()]: The XQuery syntax '/ function ()' is not supported.
+4
source share
1 answer
 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")]'); 
+8
source

Source: https://habr.com/ru/post/1401208/


All Articles