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