XQUERY - How to use the sql:variable in 'value()' function?

后端 未结 2 528
情歌与酒
情歌与酒 2020-12-19 09:10

The query below is trying to select a child node of a given Node. How do I use a variable instead of hard coding the child node such that I can pass them as parameters in a

2条回答
  •  北荒
    北荒 (楼主)
    2020-12-19 10:01

    declare @Node varchar(50)
    set @Node = 'TimeZone'
    declare @ChildName varchar(50)
    set @ChildName='HiddenName'
    
    ;WITH XMLNAMESPACES(DEFAULT 'http://tempuri.org')
    select N.value('.', 'varchar(100)') as Value
    from @T as T
      cross apply T.XMLCol.nodes('//*[local-name()=sql:variable("@Node")]/children/*[local-name(.)=sql:variable("@ChildName")]') as X(N)
    

提交回复
热议问题