Stored Procedure and populating a Temp table from a linked Stored Procedure with parameters

后端 未结 5 2256
轻奢々
轻奢々 2020-12-19 08:02

I have a Stored Procedure (SP) in which I pass in one value. In this SP, I am trying to create/populate a Temp Table from the result of another SP that is on a Linked/remote

5条回答
  •  醉酒成梦
    2020-12-19 08:05

    With the usual disclaimers about guarding dynamic SQL, you can do this without OPENQUERY etc. Just call sp_executesql remotely:

    DECLARE @sql NVARCHAR(MAX);
    SET @sql = N'EXEC thelinkedSPname ' + @param1 + ';';
    INSERT #temptable EXEC [LinkedServerName].database.dbo.sp_executesql @sql;
    

提交回复
热议问题