SQL XML Xquery 在节点选择中使用变量进行数据查询?

发布于 2024-11-06 03:23:56 字数 527 浏览 0 评论 0原文

我显然错过了我面前的一些东西,但是我有这个 SQL 2008 XML 查询,如下所示:

select distinct cast(customFields_xml.query('data(/root/cf_item_type)') as varchar) as c1
from designs

..我实际上想要实现的是使“cf_item_type”成为一个变量,因为我想将节点传递为过程的参数..

所以实际上,我试图得到类似的结果:

(@cf将作为参数传递,但声明例如使用)

declare @cf varchar
set @cf='cf_item_type'
select distinct cast(customFields_xml.query('data(/root/@cf)') as varchar) as cloth from designs

..所以你可以看到我正在尝试使用@比照xquery 语句中的变量..

任何指针/帮助都会很棒!

I am obviously missing something right in front of me, however I have this SQL 2008 XML query as follows:

select distinct cast(customFields_xml.query('data(/root/cf_item_type)') as varchar) as c1
from designs

.. what I am actually trying to achieve is to make the "cf_item_type" a variable, because I want to pass in the node as a param to a proc..

So in reality, I am trying to end up with something like:

(@cf would be passed as a param, but declaring for example use)

declare @cf varchar
set @cf='cf_item_type'
select distinct cast(customFields_xml.query('data(/root/@cf)') as varchar) as cloth from designs

.. So you can see I am trying to use the @cf variable within the xquery statement..

Any pointers/help would be great!!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

苯莒 2024-11-13 03:23:56

这可能会做你想做的事。

declare @cf varchar(20)
set @cf='cf_item_type'

select distinct
  cast(customFields_xml.query(
    'data(/root/*[local-name(.) = sql:variable("@cf")])') as varchar(20)) as cloth
from designs

This might do what you want.

declare @cf varchar(20)
set @cf='cf_item_type'

select distinct
  cast(customFields_xml.query(
    'data(/root/*[local-name(.) = sql:variable("@cf")])') as varchar(20)) as cloth
from designs
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文