【问题标题】:SQL select join on xml field with xpath expressionSQL select join on xml field with xpath expression
【发布时间】:2013-10-25 12:41:58
【问题描述】:

我有一个可以从 xml 返回结果的查询:

declare @xml xml

select @xml = data from files where id = 1234

select
    children.p.value('./speed[1]','float')
from @xml.nodes('root/children') as children(p)
where
    children.p.value('./name[1]','nvarchar(max)') = 'something'

在我的例子中返回一个值,例如3141

但是,我想从多个 XML 中进行多次选择。

我可以选择xml数据为

select id, cast(data as xml) as xml
from files
where id in (1005,51,968,991,992,993,969,970) --for example

我想一定有某种 JOIN 将应用我的表达式并为表中的每个 xml 变量返回一个项目,但我不确定如何。

【问题讨论】:

    标签: sql sql-server xml xpath sqlxml


    【解决方案1】:

    使用应用:

    select
        f.id, children.p.value('./speed[1]','float')
    from files as f
        outer apply (select cast(f.data as xml) as xml) as x
        outer apply x.xml.nodes('root/children') as children(p)
    where
         f.id in (1005,51,968,991,992,993,969,970) and
         children.p.value('./name[1]','nvarchar(max)') = 'something'
    

    【讨论】:

      猜你喜欢
      • 2018-05-13
      • 1970-01-01
      • 2012-06-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多