|
楼主 |
发表于 2009-5-31 14:01:08
|
显示全部楼层
(select bas.custname
from bd_cubasdoc bas, bd_cumandoc cum
where bas.pk_cubasdoc = cum.pk_cubasdoc
and nvl(bas.dr, 0) = 0
and nvl(cum.dr, 0) = 0
and cum.pk_corp = zl_ta.pk_corp
and cum.pk_cumandoc = zl_ta.pk_cust) custname,
(select bas.custcode
from bd_cubasdoc bas, bd_cumandoc cum
where bas.pk_cubasdoc = cum.pk_cubasdoc
and nvl(bas.dr, 0) = 0
and nvl(cum.dr, 0) = 0
and cum.pk_corp = zl_ta.pk_corp
and cum.pk_cumandoc = zl_ta.pk_cust) custcode,
0 qc,
0 jfby,
0 jflj,
0 dfby,
0 dflj,
0 qm,
0 wkp,
0 onemonth,
0 twomonth,
sum(zl_ta.ysje) threemonth,
0 fourtosixmonth,
0 sevenmonth
from (select zb.dwbm pk_corp,
fb.ksbm_cl pk_cust,
fb.fb_oid fboid,
(fb.jfbbje -
nvl((select sum(clb.jfclbbje)
from arap_djclb clb
where clb.fb_oid = fb.fb_oid
and clb.djbh like 'YS%'
and clb.clrq >=
(select lasttwomonthbegin
from shyw_datetime
where bdate = substr(#dateto#, 0, 7))
and clb.clrq <=
(substr(#dateto#, 0, 7) || '-31')
and clb.dwbm = fb.dwbm),
0)) ysje
from arap_djfb fb, arap_djzb zb
where zb.vouchid = fb.vouchid
and nvl(fb.dr, 0) = 0
and zb.djlxbm = 'D0'
and fb.dwbm in (#corp#)
and zb.djrq >=
(select lasttwomonthbegin
from shyw_datetime
where bdate = substr(#dateto#, 0, 7))
and zb.djrq <=
(select lasttwomonthend
from shyw_datetime
where bdate = substr(#dateto#, 0, 7))) zl_ta
group by zl_ta.pk_corp, zl_ta.pk_cust, zl_ta.pk_corp
union all
select zl_ta.pk_corp,
(select termname
from bd_payterm
where nvl(dr, 0) = 0
and pk_payterm =
(select cm.pk_payterm
from bd_cubasdoc cb, bd_cumandoc cm
where cb.pk_cubasdoc = cm.pk_cubasdoc
and nvl(cb.dr, 0) = 0
and nvl(cm.dr, 0) = 0
and cm.pk_cumandoc = zl_ta.pk_cust)) termname,
(select psnname
from bd_psndoc
where pk_psndoc =
(select cm.pk_resppsn1
from bd_cubasdoc cb, bd_cumandoc cm
where cb.pk_cubasdoc = cm.pk_cubasdoc
and nvl(cb.dr, 0) = 0
and nvl(cm.dr, 0) = 0
and cm.pk_cumandoc = zl_ta.pk_cust)) ryname,
(select bas.custname
from bd_cubasdoc bas, bd_cumandoc cum
where bas.pk_cubasdoc = cum.pk_cubasdoc
and nvl(bas.dr, 0) = 0
and nvl(cum.dr, 0) = 0
and cum.pk_corp = zl_ta.pk_corp
and cum.pk_cumandoc = zl_ta.pk_cust) custname,
(select bas.custcode
from bd_cubasdoc bas, bd_cumandoc cum
where bas.pk_cubasdoc = cum.pk_cubasdoc
and nvl(bas.dr, 0) = 0
and nvl(cum.dr, 0) = 0
and cum.pk_corp = zl_ta.pk_corp
and cum.pk_cumandoc = zl_ta.pk_cust) custcode,
0 qc,
0 jfby,
0 jflj,
0 dfby,
0 dflj,
0 qm,
0 wkp,
0 onemonth,
0 twomonth,
0 threemonth,
sum(zl_ta.ysje) fourtosixmonth,
0 sevenmonth
from (select zb.dwbm pk_corp,
fb.ksbm_cl pk_cust,
fb.fb_oid fboid,
(fb.jfbbje -
nvl((select sum(clb.jfclbbje)
from arap_djclb clb
where clb.fb_oid = fb.fb_oid
and clb.djbh like 'YS%'
and clb.clrq >=
(select lastfivemonthbegin
from shyw_datetime
where bdate = substr(#dateto#, 0, 7))
and clb.clrq <=
(substr(#dateto#, 0, 7) || '-31')
and clb.dwbm = fb.dwbm),
0)) ysje
from arap_djfb fb, arap_djzb zb
where zb.vouchid = fb.vouchid
and nvl(fb.dr, 0) = 0
and zb.djlxbm = 'D0'
and fb.dwbm in (#corp#)
and zb.djrq >=
(select lastfivemonthbegin
from shyw_datetime
where bdate = substr(#dateto#, 0, 7))
and zb.djrq <=
(select lastthreemonthend
from shyw_datetime
where bdate = substr(#dateto#, 0, 7))) zl_ta
group by zl_ta.pk_corp, zl_ta.pk_cust, zl_ta.pk_corp
union all
select zl_ta.pk_corp,
(select termname
from bd_payterm
where nvl(dr, 0) = 0
and pk_payterm =
(select cm.pk_payterm
from bd_cubasdoc cb, bd_cumandoc cm
where cb.pk_cubasdoc = cm.pk_cubasdoc
and nvl(cb.dr, 0) = 0
and nvl(cm.dr, 0) = 0
and cm.pk_cumandoc = zl_ta.pk_cust)) termname,
(select psnname
from bd_psndoc
where pk_psndoc =
(select cm.pk_resppsn1
from bd_cubasdoc cb, bd_cumandoc cm
where cb.pk_cubasdoc = cm.pk_cubasdoc
and nvl(cb.dr, 0) = 0
and nvl(cm.dr, 0) = 0
and cm.pk_cumandoc = zl_ta.pk_cust)) ryname,
(select bas.custname
from bd_cubasdoc bas, bd_cumandoc cum
where bas.pk_cubasdoc = cum.pk_cubasdoc
and nvl(bas.dr, 0) = 0
and nvl(cum.dr, 0) = 0
and cum.pk_corp = zl_ta.pk_corp
and cum.pk_cumandoc = zl_ta.pk_cust) custname,
(select bas.custcode
from bd_cubasdoc bas, bd_cumandoc cum
where bas.pk_cubasdoc = cum.pk_cubasdoc
and nvl(bas.dr, 0) = 0
and nvl(cum.dr, 0) = 0
and cum.pk_corp = zl_ta.pk_corp
and cum.pk_cumandoc = zl_ta.pk_cust) custcode,
0 qc,
0 jfby,
0 jflj,
0 dfby,
0 dflj,
0 qm,
0 wkp,
0 onemonth,
0 twomonth,
0 threemonth,
0 fourtosixmonth,
sum(zl_ta.ysje) sevenmonth
from (select zb.dwbm pk_corp,
fb.ksbm_cl pk_cust,
fb.fb_oid fboid,
(fb.jfbbje -
nvl((select sum(clb.jfclbbje)
from arap_djclb clb
where clb.fb_oid = fb.fb_oid
and clb.djbh like 'YS%'
and clb.clrq <=
(substr(#dateto#, 0, 7) || '-31')
and clb.dwbm = fb.dwbm),
0)) ysje
from arap_djfb fb, arap_djzb zb
where zb.vouchid = fb.vouchid
and nvl(fb.dr, 0) = 0
and zb.djlxbm = 'D0'
and fb.dwbm in (#corp#)
and zb.djrq <=
(select lastsixmonthend
from shyw_datetime
where bdate = substr(#dateto#, 0, 7))) zl_ta
group by zl_ta.pk_corp, zl_ta.pk_cust, zl_ta.pk_corp) tsu
group by tsu.pk_corp, tsu.ryname, tsu.trmname, tsu.custname,tsu.custcode |
|