【问题标题】:Error "must declare scalar variable" when using a in memory table in T-SQL在 T-SQL 中使用内存表时出现错误“必须声明标量变量”
【发布时间】:2016-08-29 15:26:55
【问题描述】:

我正在将 varchar 转换为 xml 并将其放入内存表中以便我可以查询它,但我不断收到错误

必须声明标量变量

这是我的代码:

Declare @templatexml table (CurrentTemplateXml XML Not Null)

insert into @templatexml(CurrentTemplateXml)
    select 
        convert(xml, convert(nvarchar(max), O.CurrentTemplateXml))
    From 
        BMObject O 


select * 
from 
    (select 
         T.C.value('@Name', 'nvarchar(max)') as name
     from 
         @templatexml.nodes('(ObjectTemplate/Sections/Section)') as T(C)
    ) as temp

【问题讨论】:

    标签: sql sql-server xml tsql


    【解决方案1】:

    您声明了表变量@templatexml,但您将其用作xml 类型的变量。

    好像代替了

    select T.C.value('@Name', 'nvarchar(max)') as name
    from @templatexml.nodes('(ObjectTemplate/Sections/Section)') as T(C)
    

    你想用

    select T.C.value('@Name', 'nvarchar(max)') as name
    from @templatexml tx
        cross apply tx.CurrentTemplateXml.nodes('(ObjectTemplate/Sections/Section)') as T(C)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多