select * from (exec sp_test)
錯誤
Server: Msg 156, Level 15, State 1, Procedure test3, Line 36
Incorrect syntax near the keyword 'exec'.
Server: Msg 170, Level 15, State 1, Procedure test3, Line 36
Line 36: Incorrect syntax near ')'.
1.可通过以下格式将结果集插入到表:
insert into 表 exec 存储过程
例:
create table #t(...)
insert into #t exec sp_test
select * from #t
drop table #t
2.直接select into到临时表:
select * into #t from OPENROWSET(
'SQLOLEDB','SERVER=server;uid=sa;pwd=123;Database=testdb',
'SET FMTONLY OFF;set nocount on;exec sp_test') as a
select * from #t
drop table #t