当前位置: 代码迷 >> SQL >> SQL存储过程编撰,包含临时表
  详细解决方案

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

热度:96   发布时间:2016-05-05 10:02:29.0
SQL存储过程编写,包含临时表
create proc R_ProductUse_M(@id1 int,@id2 int,@id3 int)asbegin---临时表1select a.id1,b.id2,c.id3 into #linshi_1from table_a as a,table_b as b,table_c as cwhere a.id1=@id2---临时表2select c.id3,sum(a.l2),month(b.l3),b.l1 into #linshi_2from table_a as a,table_b as b,table_c as cwhere [email protected]group by month(b.13)---结果select #linshi_1.id1,#linshi_1.id2from #linshi_1 left join #linshi_2 on #linshi_1.id1=#linshi_2.id2endgo

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

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

  相关解决方案