金蝶K3成本费用统计表
根据成本系统的费用归集,按照年度统计出各月份的各个部门的费用
create proc stkd_成本费用统计表
@year int
as
set nocount on
create table #aa(
fdeptid int,
fdeptnum varchar(50),
fdeptname varchar(50),
fexpense varchar(50),
f1 decimal(18,2) default(0),
f2 decimal(18,2) default(0),
f3 decimal(18,2) default(0),
f4 decimal(18,2) default(0),
f5 decimal(18,2) default(0),
f6 decimal(18,2) default(0),
f7 decimal(18,2) default(0),
f8 decimal(18,2) default(0),
f9 decimal(18,2) default(0),
f10 decimal(18,2) default(0),
f11 decimal(18,2) default(0),
f12 decimal(18,2) default(0),
fall decimal(18,2) default(0)
)
insert into #aa
select fdeptid,td.fnumber,td.fname,ce.fname,
sum(case when fperiod=1 then famount else 0 end),
sum(case when fperiod=2 then famount else 0 end),
sum(case when fperiod=3 then famount else 0 end),
sum(case when fperiod=4 then famount else 0 end),
sum(case when fperiod=5 then famount else 0 end),
sum(case when fperiod=6 then famount else 0 end),
sum(case when fperiod=7 then famount else 0 end),
sum(case when fperiod=8 then famount else 0 end),
sum(case when fperiod=9 then famount else 0 end),
sum(case when fperiod=10 then famount else 0 end),
sum(case when fperiod=11 then famount else 0 end),
sum(case when fperiod=12 then famount else 0 end),
sum(famount)
from CBCostExpenseInfo cc,cbExpense ce,t_department td
where cc.fexpid=ce.fitemid and cc.fdeptid=td.fitemid and fyear=@year
group by cc.fdeptid,td.fnumber,td.fname,ce.fname
select fdeptnum as 部门代码,fdeptname as 部门名称,fexpense as 费用,f1 as 一月,f2 as 二月,f3 as 三月,f4 as 四月,
f5 as 五月,f6 as 六月,f7 as 七月,f8 as 八月,f9 as 九月,f10 as 十月,f11 as 十一月,f12 as 十二月,fall as 合计
from #aa
order by fdeptnum
GO

浙公网安备 33010602011771号