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

后端 未结 5 2250
轻奢々
轻奢々 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:04

    With some care you could use a shared temp table:

    DECLARE @Qry AS VARCHAR(MAX)
    SET @Qry = 'select * into ##tempTable from openquery([the Linked server],''exec thelinkedSPname ' + @param1 + ''')'
    EXEC (@Qry)
    
    -- Now just use the shared Temp table, or I suppose you could copy it to a temp table just as you wanted it:
    
    SELECT * INTO #tempTable FROM( SELECT * FROM ##tempTable)tbl
    DROP TABLE ##tempTable
    

提交回复
热议问题