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 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.id2endgo
一个#为局部变量、这样的临时表只能在该存储过程中使用
二个##为全局临时表,可以在存储过程外使用,需要手动删除 drop table ##表名
新闻热点
疑难解答