如果是追加: insert into #temp select * from yourtable where ...
SELECT * INTO #TEM1 FROM ( select a.class_name as "班级名称" , c.specialty_name as "专业名称", count(b.Invoice_CID) as "收费人数",sum(b.Invoice_Charge) as "收费金额", (select count(Invoice_CID) as "退费人数" from SOFOM_Inovice where Invoice_State = 0 and Invoice_Class=b.Invoice_Class), (select sum(Invoice_Charge) as "退费金额" from SOFOM_Inovice where Invoice_State = 0 and Invoice_Class=b.Invoice_Class) from sofom_class a join SOFOM_Inovice b on b.invoice_class = a.class_id join sofom_specialty c on a.class_specialty = c.specialty_id where b.Invoice_CTime='2004-2-16' or b.Invoice_QTime='2004-2-12' group by a.class_name,c.specialty_name,b.Invoice_class ) A
select ...... into #temp from .... where....
如果已经创建了该表 insert into #temp select * from yourtable where ... 如果没有该表 select * into #temp from yourtable where ...
insert into #temp select * from yourtable where ...
(
select a.class_name as "班级名称" , c.specialty_name as "专业名称",
count(b.Invoice_CID) as "收费人数",sum(b.Invoice_Charge) as "收费金额",
(select count(Invoice_CID) as "退费人数" from SOFOM_Inovice where Invoice_State = 0 and Invoice_Class=b.Invoice_Class),
(select sum(Invoice_Charge) as "退费金额" from SOFOM_Inovice where Invoice_State = 0 and Invoice_Class=b.Invoice_Class)
from sofom_class a join SOFOM_Inovice b
on b.invoice_class = a.class_id
join sofom_specialty c on a.class_specialty = c.specialty_id
where b.Invoice_CTime='2004-2-16' or b.Invoice_QTime='2004-2-12'
group by a.class_name,c.specialty_name,b.Invoice_class
) A
insert into #temp select * from yourtable where ...
如果没有该表
select * into #temp from yourtable where ...