关于把查出的结果导入到一个临时表里的问题!
我现在用一个sql语句查了n张表,想把查询的结果导到一个历史表里,例如
select c.BranchName as 公司,
sum(case endreason when '总人数' then 1 else 0 end) 总人数,
sum(case endreason when '全勤人数' then 1 else 0 end) 全勤人数
from
表1 la left join 表2 a on la.id=a.id left join 表3 b on a.depID=b.depid left join 表4 c on b.name=c.name group by c.name , c.nameid order by c.nameid asc
大体就是这个意思,反正这个sql语句能查出我需要的结果集,但是我把这个结果填加到一个临时表里(临时表目前不存在),请问怎么搞定?谢谢~
------解决方案--------------------select
into #tablename
from
楼主勤快点,帮助手册里有.
------解决方案--------------------insert into #
select c.BranchName as 公司,
sum(case endreason when '总人数 ' then 1 else 0 end) 总人数,
sum(case endreason when '全勤人数 ' then 1 else 0 end) 全勤人数
from
表1 la left join 表2 a on la.id=a.id left join 表3 b on a.depID=b.depid left join 表4 c on b.name=c.name group by c.name , c.nameid order by c.nameid asc
------解决方案--------------------SQL code
--try
select c.BranchName as 公司,
sum(case endreason when '总人数' then 1 else 0 end) 总人数,
sum(case endreason when '全勤人数' then 1 else 0 end) 全勤人数
into #tb
from 表1 la left join 表2 a on la.id=a.id
left join 表3 b on a.depID=b.depid
left join 表4 c on b.name=c.name
group by c.name , c.nameid
order by c.nameid asc
------解决方案--------------------
INSERT yddb (Device_Name,Device_Tag,Device_Memo,Entry_Time,Device_Location,Entry_Price,Device_Keeper,Device_Dept)
SELECT Device_Name,Device_Tag,Device_Memo,Entry_Date,Device_Location,Entry_Price,KeeperName,Device_Dept from Entry_Device_Sheet where Device_Keeper='gy'
大概的意思,你自己调整下就OK