请教存储过程 临时表 添加新列
从表1中select出如下数据(Table1):
Select Date, volume from Table1
Date volume
2007-7-1 100
2007-7-2 80
2007-7-5 20
2007-7-6 5
2007-7-9 25
2007-7-10 35
从表2中select出如下数据(Table2):
Select Date, volume from Table2
Date volume
2007-7-1 30
2007-7-3 80
2007-7-5 60
2007-7-6 5
2007-7-8 25
从表3中select出如下数据(Table3):
Select Date, volume from Table3
Date volume
2007-7-2 3
2007-7-3 8
2007-7-4 6
2007-7-6 5
2007-7-11 24
有很多表Table....类似上面select 出类似的数据。
我的问题:
能否建立一个存储过程,建立一个临时表,临时表有3个字段Date,Volume,Type.Type说明来自哪一个表。
最后的临时表中的内容为:
Date volume Type
2007-7-1 100 T1
2007-7-2 80 T1
2007-7-5 20 T1
2007-7-6 5 T1
2007-7-9 25 T1
2007-7-10 35 T1
2007-7-1 30 T2
2007-7-3 80 T2
2007-7-5 60 T2
2007-7-6 5 T2
2007-7-8 25 T2
2007-7-2 3 T3
2007-7-3 8 T3
2007-7-4 6 T3
2007-7-6 5 T3
2007-7-11 24 T3
------解决方案--------------------Select Date, volume, 'T1 ' as type into #tmp from Table1
union all
Select Date, volume, 'T2 ' as type from Table2
union all
Select Date, volume, 'T3 ' as type from Table3
----查看
select * from #tmp
------解决方案--------------------select *, 't1 ' type from t1
union all
select *, 't2 ' type from t2
union all
select *, 't3 ' type from t3
------解决方案--------------------create proc sp_ins
as
begin
if object_id( '#tmp ') i