XQUERY SQL - How to pass individual node element(s) as variables?

核能气质少年 提交于 2019-12-10 17:56:14

问题


Is there an alternate way to pass node elements dynamically than the one shown below - ?

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

For e.g., even if I am trying to give the fully qualified path, I do not want to hard code the node elements, instead I would like to pass them individually as parameters.

Under the section -

Example: Query Using sp_executesql

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

it says -

query contains wildcards (*) and node tests using node names and is hard to optimize well. Consequently, it performs much worse than the original query and the query construction approach.


回答1:


May be like this:

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


来源:https://stackoverflow.com/questions/7038038/xquery-sql-how-to-pass-individual-node-elements-as-variables

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