码迷,mamicode.com
首页 > 数据库 > 详细

SQL存储过程编写,包含临时表

时间:2015-08-20 10:17:44      阅读:129      评论:0      收藏:0      [点我收藏+]

标签:

create proc R_ProductUse_M(@id1 int,@id2 int,@id3 int)
as
begin
---临时表1
select a.id1,b.id2,c.id3 into #linshi_1
from table_a as a,table_b as b,table_c as c
where a.id1=@id2---临时表2
select c.id3,sum(a.l2),month(b.l3),b.l1 into #linshi_2
from table_a as a,table_b as b,table_c as c
where a.id1=@id1group by month(b.13)
---结果
select #linshi_1.id1,#linshi_1.id2from #linshi_1 left join #linshi_2 on #linshi_1.id1=#linshi_2.id2
end
go

一个#为局部变量、这样的临时表只能在该存储过程中使用

二个##为全局临时表,可以在存储过程外使用,需要手动删除 drop table ##表名

SQL存储过程编写,包含临时表

标签:

原文地址:http://www.cnblogs.com/lovejunjuan/p/4744174.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!