查询中需要创建临时表,并且要将多个查询结果插入临时表中

drop table ##tablename -- 查询前先删除 
select * into ##tablename from ( --创建表,第一次插入数据 
select s.CreateDt ,m.Type, m.Pid,c.Pro_FullName,c.Pro_Id,m.UnitId,b.Pro_Num,b.Price,b.Remark,b.FullPrice  from SellList s, SellDetail b, ProductDetail c , MonthlyStatement m where s.Id=b.SellId  and c.Id=b.Pro_Id  and  s.SellId = m.Pid  and m.Pid like 'xsd%' ) as table1  

insert into ##tablename  --第二次插入数据 
select s.CreateDt,m.Type, m.Pid,c.Pro_FullName,c.Pro_Id,m.UnitId,b.Pro_Num,b.Price,b.Remark,b.FullPrice  from SellList s, SellDetail b, ProductDetail c , MonthlyStatement m where s.Id=b.SellId  and c.Id=b.Pro_Id  and  s.SellId = m.Pid  and m.Pid like 'xsd%' 
--查询临时表 
select * from ##tablename where  1>0 order by UnitId  go