Exec stored procedure into dynamic temp table

后端 未结 4 941
[愿得一人]
[愿得一人] 2020-12-10 03:55

To my knowledge; what I want to do is not possible in sql, but it is worth asking you guys.

Lets say I have a stored procedure abc that returns columns Id and Value.

相关标签:
4条回答
  • 2020-12-10 04:20
    SELECT * INTO #TempTable 
    FROM OPENROWSET
    ('SQLNCLI','Server=(local)\SQL2008R2;Trusted_Connection=yes;',
         'EXEC OtherDb.DataProd.abc')
    
    SELECT * FROM #TempTable
    
    0 讨论(0)
  • 2020-12-10 04:30

    Insert into a temp table. I know this works in 2008 and above, not sure about 2005. Your temp table columns must match your Stored Proc columns.

    create table #mytable (custid int,company varchar(50),contactname varchar(50)
                    , phone varchar(50),address1 varchar(50)
                    , address2 varchar(50),city varchar(50)
                    ,st varchar(2),zip varchar(20))
    
    insert into #mytable (custid,company,contactname,phone,address1,address2,city,st,zip)
    exec dbo.sp_Node_CustomerList_wService @segid = 1
    
    select * from #mytable
    where custid = 5
    
    drop table #mytable
    
    0 讨论(0)
  • 2020-12-10 04:35

    it is better and easy way to use openrowset

    SELECT * INTO #tempTable FROM OPENROWSET('SQLNCLI', 'Server=localhost;Trusted_Connection=yes;', 'EXEC OtherDb.DataProd.abc')

    0 讨论(0)
  • 2020-12-10 04:40

    Otherwise have a look over here, there are more options explained there: Insert results of a stored procedure into a temporary table?

    0 讨论(0)
提交回复
热议问题