日期:2014-05-17 浏览次数:20520 次
create table #rourou
(
f_spbm varchar(50) not null,
f_qcsl float,
)
declare @starttime datetime
declare @endtime datetime
declare @startny varchar(10)
declare @ts int
declare @startday varchar(10)
declare @null varchar(10)
set @starttime='20121022'
set @endtime='20121120'
set @startny=(select left(convert(varchar(10),@starttime,112),6))
set @ts=(select datediff(day,@starttime,@endtime))+1
set @startday=(select convert(varchar(10),@starttime,112))
insert into #rourou exec('select a.f_spbm,isnull(c.f_qcsl+d.f_rhj,0) f_qmsl from tbspda a
left join tb'+@startny+'_yhj c on a.f_spbm=c.f_spbm
left join (select f_spbm,isnull(sum(f_jhsl+f_brsl+f_sysl+f_pssl-f_xssl-f_bcsl-f_shsl-f_phsl),0) f_rhj from tb'+@startny+'_rhj group by f_spbm) d on a.f_spbm=d.f_spbm where datalength(a.f_cwbm)<>0')
while @ts>'0'
begin
declare @jsny varchar(10)
declare @jsday varchar(10)
set @jsny=(select left(convert(varchar(10),@starttime,112),6))
set @jsday=(select convert(varchar(10),@starttime,112))
insert into #rourou exec('select f_spbm@ts*isnull(b.f_Jhsl+b.f_Brsl+b.f_Sysl+b.f_Pssl-b.f_Xssl-b.f_Bcsl-b.f_Shsl-b.f_Phsl,0) from tb'+@jsny+'_rhj where b.f_rq=@jsday')
set @starttime=@starttime+1
set @ts=@ts-1
end
select f_spbm,sum(f_qcsl) from #rourou group by f_spbm
drop table #rourou