注册 登录
编程论坛 SQL Server论坛

如何将存储过程的结果集 快速插入临时表

ren198407 发布于 2016-07-08 15:44, 3407 次点击
如题
2 回复
#2
mywisdom882016-07-08 16:35
看不出你想做什么
在SQL2000中,在表名前面加#就是临时表,断开连接后,临时表就消失的
如果你想在过程中保存临时表,在过程结束前使用,可以这样,如:
create proc test1
@id1 int
AS
begin
IF OBJECT_ID('tempdb..#test') is not null
   drop table #test
create table #test(id int,name varchar(20),sex varchar(4))
insert into #test select id,name,sex from stu where id=@id1 --把固定表 stu查询结果集保存到 临时表 #test
end




#3
ren1984072016-07-09 12:56
回复 2楼 mywisdom88
不好意思 我没有说清楚。
不想创建临时表,因为存储过程的结果 字段太多。
直接用select  into 临时表 from 存储过程,这样可以吗。
尝试总是不成功
1