金蝶K3财务付款日程表
根据应付系统采购发票上的应付日期和供应商信息的信用期限按照月度统计出每日的应付款信息
CREATE proc stkd_财务_付款日程表 --stkd_财务_付款日程表 '2006-11-01','2006-11-30'
@begdate datetime,
@enddate datetime
as
set nocount on

create table #aa(
fnumber varchar(80),
fname varchar(80),
fitemid varchar(50),
fdq decimal(18,2) default(0),
fdate1 decimal(18,2) default(0),
fdate2 decimal(18,2) default(0),
fdate3 decimal(18,2) default(0),
fdate4 decimal(18,2) default(0),
fdate5 decimal(18,2) default(0),
fdate6 decimal(18,2) default(0),
fdate7 decimal(18,2) default(0),
fdate8 decimal(18,2) default(0),
fdate9 decimal(18,2) default(0),
fdate10 decimal(18,2) default(0),
fdate11 decimal(18,2) default(0),
fdate12 decimal(18,2) default(0),
fdate13 decimal(18,2) default(0),
fdate14 decimal(18,2) default(0),
fdate15 decimal(18,2) default(0),
fdate16 decimal(18,2) default(0),
fdate17 decimal(18,2) default(0),
fdate18 decimal(18,2) default(0),
fdate19 decimal(18,2) default(0),
fdate20 decimal(18,2) default(0),
fdate21 decimal(18,2) default(0),
fdate22 decimal(18,2) default(0),
fdate23 decimal(18,2) default(0),
fdate24 decimal(18,2) default(0),
fdate25 decimal(18,2) default(0),
fdate26 decimal(18,2) default(0),
fdate27 decimal(18,2) default(0),
fdate28 decimal(18,2) default(0),
fdate29 decimal(18,2) default(0),
fdate30 decimal(18,2) default(0),
fdate31 decimal(18,2) default(0),
fall decimal(18,2) default(0)
)
insert into #aa(fitemid,fdq,fdate1,fdate2,fdate3,fdate4,fdate5,fdate6,fdate7,fdate8,fdate9,fdate10,fdate11,fdate12,
fdate13,fdate14,fdate15,fdate16,fdate17,fdate18,fdate19,fdate20,fdate21,fdate22,fdate23,fdate24,fdate25,fdate26,
fdate27,fdate28,fdate29,fdate30,fdate31,fall)
select ts.fitemid,
sum(case when ta.fdate<@begdate then ta.fremainamount else 0 end),
sum(case when ta.fdate>=@begdate and ta.fdate<=@enddate and day(ta.fdate)=1 then ta.fremainamount else 0 end),
sum(case when ta.fdate>=@begdate and ta.fdate<=@enddate and day(ta.fdate)=2 then ta.fremainamount else 0 end),
sum(case when ta.fdate>=@begdate and ta.fdate<=@enddate and day(ta.fdate)=3 then ta.fremainamount else 0 end),
sum(case when ta.fdate>=@begdate and ta.fdate<=@enddate and day(ta.fdate)=4 then ta.fremainamount else 0 end),
sum(case when ta.fdate>=@begdate and ta.fdate<=@enddate and day(ta.fdate)=5 then ta.fremainamount else 0 end),
sum(case when ta.fdate>=@begdate and ta.fdate<=@enddate and day(ta.fdate)=6 then ta.fremainamount else 0 end),
sum(case when ta.fdate>=@begdate and ta.fdate<=@enddate and day(ta.fdate)=7 then ta.fremainamount else 0 end),
sum(case when ta.fdate>=@begdate and ta.fdate<=@enddate and day(ta.fdate)=8 then ta.fremainamount else 0 end),
sum(case when ta.fdate>=@begdate and ta.fdate<=@enddate and day(ta.fdate)=9 then ta.fremainamount else 0 end),
sum(case when ta.fdate>=@begdate and ta.fdate<=@enddate and day(ta.fdate)=10 then ta.fremainamount else 0 end),
sum(case when ta.fdate>=@begdate and ta.fdate<=@enddate and day(ta.fdate)=11 then ta.fremainamount else 0 end),
sum(case when ta.fdate>=@begdate and ta.fdate<=@enddate and day(ta.fdate)=12 then ta.fremainamount else 0 end),
sum(case when ta.fdate>=@begdate and ta.fdate<=@enddate and day(ta.fdate)=13 then ta.fremainamount else 0 end),
sum(case when ta.fdate>=@begdate and ta.fdate<=@enddate and day(ta.fdate)=14 then ta.fremainamount else 0 end),
sum(case when ta.fdate>=@begdate and ta.fdate<=@enddate and day(ta.fdate)=15 then ta.fremainamount else 0 end),
sum(case when ta.fdate>=@begdate and ta.fdate<=@enddate and day(ta.fdate)=16 then ta.fremainamount else 0 end),
sum(case when ta.fdate>=@begdate and ta.fdate<=@enddate and day(ta.fdate)=17 then ta.fremainamount else 0 end),
sum(case when ta.fdate>=@begdate and ta.fdate<=@enddate and day(ta.fdate)=18 then ta.fremainamount else 0 end),
sum(case when ta.fdate>=@begdate and ta.fdate<=@enddate and day(ta.fdate)=19 then ta.fremainamount else 0 end),
sum(case when ta.fdate>=@begdate and ta.fdate<=@enddate and day(ta.fdate)=20 then ta.fremainamount else 0 end),
sum(case when ta.fdate>=@begdate and ta.fdate<=@enddate and day(ta.fdate)=21 then ta.fremainamount else 0 end),
sum(case when ta.fdate>=@begdate and ta.fdate<=@enddate and day(ta.fdate)=22 then ta.fremainamount else 0 end),
sum(case when ta.fdate>=@begdate and ta.fdate<=@enddate and day(ta.fdate)=23 then ta.fremainamount else 0 end),
sum(case when ta.fdate>=@begdate and ta.fdate<=@enddate and day(ta.fdate)=24 then ta.fremainamount else 0 end),
sum(case when ta.fdate>=@begdate and ta.fdate<=@enddate and day(ta.fdate)=25 then ta.fremainamount else 0 end),
sum(case when ta.fdate>=@begdate and ta.fdate<=@enddate and day(ta.fdate)=26 then ta.fremainamount else 0 end),
sum(case when ta.fdate>=@begdate and ta.fdate<=@enddate and day(ta.fdate)=27 then ta.fremainamount else 0 end),
sum(case when ta.fdate>=@begdate and ta.fdate<=@enddate and day(ta.fdate)=28 then ta.fremainamount else 0 end),
sum(case when ta.fdate>=@begdate and ta.fdate<=@enddate and day(ta.fdate)=29 then ta.fremainamount else 0 end),
sum(case when ta.fdate>=@begdate and ta.fdate<=@enddate and day(ta.fdate)=30 then ta.fremainamount else 0 end),
sum(case when ta.fdate>=@begdate and ta.fdate<=@enddate and day(ta.fdate)=31 then ta.fremainamount else 0 end),
sum(case when ta.fdate>=@begdate and ta.fdate<=@enddate then ta.fremainamount else 0 end)
from t_rp_contact tc inner join t_RP_Plan_Ap ta on tc.fid=ta.forgid
inner join t_supplier ts on tc.fcustomer=ts.fitemid where tc.ftype =4
--where ts.f_102=40101 and ts.f_103=40103
group by ts.fitemid
update t1
set t1.fnumber=t2.fnumber,t1.fname=t2.fname
from #aa t1,t_supplier t2
where t1.fitemid=t2.fitemid
select fnumber as 编码,fname as 供应商,fdq as 到期,fdate1 as 一号,fdate2 as 二号,fdate3 as 三号,fdate4 as 四号,
fdate5 as 五号,fdate6 as 六号,fdate7 as 七号,fdate8 as 八号,fdate9 as 九号,fdate10 as 十号,
fdate11 as 十一号,fdate12 as 十二号,fdate13 as 十三号,fdate14 as 十四号,fdate15 as 十五号,fdate16 as 十六号,
fdate17 as 十七号,fdate18 as 十八号,fdate19 as 十九号,fdate20 as 二十号,fdate21 as 二一号,fdate22 as 二二号,
fdate23 as 二三号,fdate24 as 二四号,fdate25 as 二五号,fdate26 as 二六号,fdate27 as 二七号,fdate28 as 二八号,
fdate29 as 二九号,fdate30 as 三十号,fdate31 as 三一号,fall as 总计 from #aa order by fnumber
drop table #aa

GO 
浙公网安备 33010602011771号