XQUERY SQL - How to pass individual node elements as variables?

Is there an alternative way to skip node elements dynamically than the one shown below ??

select XMLTable.XMLCOL.query('//*[local-name()=sql:variable("@node")') 

For example, even if I try to give the full path, I don’t want to hardcode the node elements, instead I would like to pass them separately as parameters.

In chapter -

Example: query Using sp_executesql

@ http://msdn.microsoft.com/en-us/library/ms345118(v=sql.90).aspx

He says -

contains templates (*) and node using node names and it is difficult to optimize well. Therefore, it is much worse than the original query and the query construction approach.

+3
source share
1 answer

Maybe so:

 declare @qry nvarchar(1000) set @qry = 'select XMLCOL.query(''//' + @node + ''') from XMLTable' exec( @qry ) 
0
source

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


All Articles