SQL 如何在 Openrowset 中使用 table 变量

SQL How to use table variable in Openrowset

我使用openrowset执行OperatorsCalc程序。

如何发送声明的参数:

  1. @operators (OperatorTableType)

  2. @number (整数)

进入由 openrowset?

执行的过程
DECLARE @operators OperatorTableType
insert into @operators values ('Mr James')
insert into @operators values ('Mr Johnny')

DECLARE @number int = 3

SELECT *
INTO #MyTempTableForOperators
FROM
    OPENROWSET('SQLNCLI', 'Server=apollo;Trusted_Connection=yes;',
               'SET FMTONLY OFF; 
                SET NOCOUNT ON; 
                EXEC servername.dbname.dbo.OperatorsCalc @number @operators') -- I want to sent parameters @operators and @number in here

select * from #MyTempTableForOperators

尝试使用linked server,但如果有嵌套insert into temp.

可能会失败
CREATE TABLE #temp (...)

INSERT INTO #temp(...)
EXECUTE [servername].[dbname].[dbo].[OperatorsCalc] @number @operators;

另请阅读 How to Share Data between Stored Procedures by Erland Sommarskog。 关于OPENQUERY的章节不错。