XQUERY SQL - 如何将单个节点元素作为变量传递? [英] XQUERY SQL - How to pass individual node element(s) as variables?

查看:47
本文介绍了XQUERY SQL - 如何将单个节点元素作为变量传递?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有比下面显示的方法动态传递节点元素的替代方法 - ?

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.

在该部分下 -

示例:使用 sp_executesql 查询

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

它说 -

查询包含通配符 (*) 和使用节点名称的节点测试,并且是很难优化好.因此,它的性能比原始查询和查询构造方法.

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.

推荐答案

可能是这样的:

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

这篇关于XQUERY SQL - 如何将单个节点元素作为变量传递?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆