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

后端 未结 5 2249
轻奢々
轻奢々 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条回答
  •  -上瘾入骨i
    2020-12-19 08:15

    Two words: Dynamic Query. Try this:

    DECLARE @TSQL varchar(8000)
    SELECT  @TSQL = 'SELECT * INTO #tempTable FROM OPENQUERY([the Linked server],''exec [the Linked server].DBName.dbo.thelinkedSPname ' + @param1 + ''')'
    EXEC (@TSQL)
    

    This is well documented here: How to pass a variable to a linked server query

提交回复
热议问题