【问题标题】:Get SQL Server remote procedure result获取 SQL Server 远程过程结果
【发布时间】:2014-07-21 16:38:50
【问题描述】:

我有 2 个 SQL Server 2005,我想将数据从 A 拉到 B。

我在 B 上执行此代码:

create table #res (
   ValueID int,
   [Timestamp] varchar(32),
   RealValue float,
   Quality int,
   Flags int
);

insert into #res(ValueId, [Timestamp], [RealValue], [Quality], [Flags])
   exec ('exec [CC_ExternalBrowsing].[dbo].[cc_sp_readtags] @List=''1;2;3;4;5'', @TimeBegin=''0000-00-00 00:05:00.000'', @TimeEnd=''0000-00-00 00:00:00.000''') AT [WINCCTESZT]

select * from #res;
drop table #res

Exec 部分运行良好(没有前一个插入行)。我可以在 SSMS 中看到数据,但我无法将数据插入到临时表中

我收到此错误:

不能在事务中执行过程“sys.addlinkedserver”。

有什么想法吗?

谢谢

【问题讨论】:

    标签: sql database sql-server-2005 stored-procedures linked-server


    【解决方案1】:

    使用表值变量而不是显式 Temp 表 - 因为不能在事务中创建表。试试这个:

    declare @res table (
       ValueID     int,
       [Timestamp] varchar(32),
       RealValue   float,
       Quality     int,
       Flags       int
    );
    
    insert into @res(ValueId, [Timestamp], [RealValue], [Quality], [Flags])
       exec ('exec [CC_ExternalBrowsing].[dbo].[cc_sp_readtags] @List=''1;2;3;4;5'', @TimeBegin=''0000-00-00 00:05:00.000'', @TimeEnd=''0000-00-00 00:00:00.000''') AT [WINCCTESZT]
    
    select * from @res;
    
    -- drop table @res    -- no longer needed
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-09-18
      • 2011-08-31
      • 1970-01-01
      • 2018-07-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多