--调用例子:--原存储过程,被调用的存储过程 create proc p_1 @tablename sysname, @eventid int as set @sqlstr='select * from '+@tablename+' where eventid='+cast(@eventid as varchar) exec(@sqlstr) go --调用的存储过程: create proc p_2 as create table #t(与上面存储过程返回的表集的结构相同) insert into #t exec p_1 go
eg: create proc test as select getdate() as gd然后 declare @a table(abc datetime) insert @a exec test服务器: 消息 197,级别 15,状态 1,行 2 EXECUTE cannot be used as a source when inserting into a table variable.
insert into #aa exec(@sqlstr)
select * from #aa
#temp 的结构和返回的结果集相一致!
declare @t1 (...)
是否可行?
因为这个存储过程是经常被调用的,如果使用创建临时表,可能开销会很大。
create proc p_1
@tablename sysname,
@eventid int
as
set @sqlstr='select * from '+@tablename+' where eventid='+cast(@eventid as varchar)
exec(@sqlstr)
go
--调用的存储过程:
create proc p_2
as
create table #t(与上面存储过程返回的表集的结构相同)
insert into #t exec p_1
go
declare @t1 (...)
是否可行?
因为这个存储过程是经常被调用的,如果使用创建临时表,可能开销会很大。答:
存储过程的返回值不能存储到表变量中.
create proc test
as
select getdate() as gd然后
declare @a table(abc datetime)
insert @a exec test服务器: 消息 197,级别 15,状态 1,行 2
EXECUTE cannot be used as a source when inserting into a table variable.
不能用表变量