1. 程式人生 > >這麼長的儲存區過程讓我改,我都不知道每個表對應是幹啥的,欄位也沒有說明。真的要崩潰了。。。

這麼長的儲存區過程讓我改,我都不知道每個表對應是幹啥的,欄位也沒有說明。真的要崩潰了。。。

ALTER PROCEDURE  [dbo].[proc_yeyoo_sfdz]
@date1 varchar(40), 
@date2 varchar(40), 
@gbdm varchar(100)
as
select gbdm,sum(cz_jy_jbzc)cz_jy_jbzj,SUM(cz_jy_xmzj) cz_jy_xmzj,sum(cz_jy_jbzc)+SUM(cz_jy_xmzj) cz_jy_xj,
SUM(cz_wlzj_jy) cz_wlzj_jy,0 cz_wlzj_dwzck, 0 cz_wlzj_gzdk,SUM(cz_wlzj_jy) cz_wlzj_xj,
sum(cz_jy_jbzc)+SUM(cz_jy_xmzj)+SUM(cz_wlzj_jy) cz_zj,
SUM(cz_sjbz_by) cz_sjbz_by,SUM(cz_sjbz_lj) cz_sjbz_lj,SUM(cz_qtsr_by) cz_qtsr_by,SUM(cz_qtsr_lj) cz_qtsr_lj,SUM(cz_ysn_by) cz_ysn_by,SUM(cz_ysn_lj) cz_ysn_lj 
from (
--基本支出餘額
select @gbdm gbdm,sum(ncye)+sum(fs) as cz_jy_jbzc,0 cz_jy_xmzj,0 cz_wlzj_jy,0 cz_sjbz_by,0 cz_sjbz_lj,
0 cz_qtsr_by,0 cz_qtsr_lj,0 cz_ysn_by,0 cz_ysn_lj from (
Select dm,isnull(ncye,0) as ncye,fs=0 From user99972017..bmhz where kmdm = '20301' and dm = @gbdm
union all
Select bmry as dm,ncye = 0,(sum(isnull(d,0))-sum(isnull(j,0))) as fs From user99972017..v_zw_pzhz where kmdm = '20301' and bmry = @gbdm  and pzrq<
[email protected]
group by bmry ) aa group by dm union all --專案支出餘額 select @gbdm gbdm,0 cz_jy_jbzc,sum(ncye)+sum(fs) as cz_jy_xmzj,0 cz_wlzj_jy,0 cz_sjbz_by,0 cz_sjbz_lj, 0 cz_qtsr_by,0 cz_qtsr_lj,0 cz_ysn_by,0 cz_ysn_lj from ( Select dm,isnull(ncye,0) as ncye,fs=0 From user99972017..bmhz where kmdm = '20302' and dm = @gbdm union all Select bmry as dm,ncye = 0,(sum(isnull(d,0))-sum(isnull(j,0))) as fs From user99972017..v_zw_pzhz where kmdm = '20302' and bmry = @gbdm and pzrq<
[email protected]
group by bmry ) aa group by dm union all --往來結餘餘額 select @gbdm gbdm,0 cz_jy_jbzc,0 as cz_jy_xmzj,sum(ncye)+sum(fs) as cz_wlzj_jy,0 cz_sjbz_by,0 cz_sjbz_lj, 0 cz_qtsr_by,0 cz_qtsr_lj,0 cz_ysn_by,0 cz_ysn_lj from ( Select dm,isnull(ncye,0) as ncye,fs=0 From user99972017..bmhz where kmdm = '20303' and dm = @gbdm union all Select bmry as dm,ncye = 0,(sum(isnull(d,0))-sum(isnull(j,0))) as fs From user99972017..v_zw_pzhz where kmdm = '20303' and bmry = @gbdm and pzrq<
[email protected]
group by bmry ) aa group by dm --select @gbdm gbdm,0 cz_jy_jbzc,0 cz_jy_xmzj,(sum(jhje)-sum(zfje)) as cz_wlzj_jy,0 cz_sjbz_by,0 cz_sjbz_lj, --0 cz_qtsr_by,0 cz_qtsr_lj,0 cz_ysn_by,0 cz_ysn_lj from ( --select gbdm ,sum(je3) as jhje,zfje = 0 from z_qtykjh where def_str6 = 'over' and def_dt1>[email protected] and def_dt1<[email protected] --and gbdm = @gbdm and def_Str2 in('0302','0307') group by gbdm --union all --select gbdm,jhje = 0,SUM(je) as zfje from z_qtzjzf where def_str3 = 'over' and shr4 is null and rq >[email protected] and rq <[email protected] --and yslx in('0302','0307') and gbdm = @gbdm group by gbdm ) aa group by gbdm union all --上級補助收入 select @gbdm gbdm,0 cz_jy_jbzc,0 cz_jy_xmzj,0 cz_wlzj_jy, SUM(case when rq >[email protected] and rq <[email protected] then je end) as cz_sjbz_by,SUM(case when rq <[email protected] then je end) as cz_sjbz_lj,0 cz_qtsr_by,0 cz_qtsr_lj,0 cz_ysn_by,0 cz_ysn_lj from z_qtzjzf where def_str3 = 'over' and shr4 is null and yslx = '0303' and gbdm = @gbdm group by yslx union all --其他收入 select @gbdm gkxm,0 cz_jy_jbzc,0 cz_jy_xmzj,0 cz_wlzj_jy,0 cz_sjbz_by,0 cz_sjbz_lj, SUM(case when rq >[email protected] and rq <[email protected] then je end) as cz_qtsr_by,SUM(case when rq <[email protected] then je end) as cz_qtsr_lj,0 cz_ysn_by,0 cz_ysn_lj from z_qtzjzf where def_str3 = 'over' and shr4 is null and yslx = '0309' and gbdm = @gbdm group by yslx union all --預算內 --select @gbdm gbdm,0 cz_jy_jbzc,0 cz_jy_xmzj,0 cz_wlzj_jy,0 cz_sjbz_by,0 cz_sjbz_lj,0 cz_qtsr_by, --0 cz_qtsr_lj,SUM(case when rq >[email protected] and rq <[email protected] then je end) as cz_ysn_by,SUM(case when rq <[email protected] then je end) as cz_ysn_lj --from z_qtzjzf where def_str3 = 'over' and shr4 is null and yslx in('0101','0102','0201','08') and gbdm [email protected] group by yslx select @gbdm gbdm,0 cz_jy_jbzc,0 as cz_jy_xmzj,0 cz_wlzj_jy,0 cz_sjbz_by,0 cz_sjbz_lj, 0 cz_qtsr_by,0 cz_qtsr_lj,SUM(by0) cz_ysn_by,sum(fs) as cz_ysn_lj from ( Select bmry as dm,(sum(isnull(j,0))-sum(isnull(d,0))) as fs,sum(case when pzrq >= @date1 and pzrq<[email protected] then isnull(j,0)-isnull(d,0) end) by0 From user99992017..v_zw_pzhz where bmry = @gbdm and pzrq<[email protected] group by bmry ) aa group by dm )a group by gbdm

————————————————分割線————————————————————————————

哈哈,問題解決了,原來欄位都是存在的,只要改最上面的專案頭,把欄位設定成為自己需要的!