查询未指定现金流量的凭证原创
金蝶云社区-阿缘
阿缘
4人赞赏了该文章 661次浏览 未经作者许可,禁止转载编辑于2020年11月17日 13:31:35

select b.fdate,b.fnumber,sum(a.凭证余额) as 凭证余额,sum(a.流量表余额) as 流量表余额,sum(a.凭证余额)-sum(a.流量表余额)  as 余额


from 

(select a.fvoucherid  ,(case when a.a=0  then a.余额  else 0 end ) as 凭证余额,(case when a.a=1  then a.余额  else 0 end ) as 流量表余额


from 

(select  a.fvoucherid,sum(增加现金流)-sum(减少现金流) as 余额,0 as a from 

(select  a.fvoucherid, (case when a.a=0  then a.famount  else 0  end ) as 增加现金流,

(case when a.a=1  then a.famount  else 0  end ) as 减少现金流

from 


(select  fvoucherid,famount,0 as a from  t_voucherentry where  faccountid  in 

(select  faccountid  from  t_account  where   (fiscash=1 or fisbank=1  or  fiscashflow=1))

and fdc=1

 union  all


select  fvoucherid,famount,1  from  t_voucherentry where  faccountid  in 

(select  faccountid  from  t_account  where   (fiscash=1 or fisbank=1  or  fiscashflow=1))

and fdc=0) a ) a

group by a.fvoucherid



union all


select a.fvoucherid,  sum(a.现金量流入)-sum(a.现金量流出) as 现金流量余额,1 from 


(select a.fvoucherid,(case  when a.a=0  then a.famount  else  0  end ) 现金量流入,

(case  when a.a=1  then a.famount  else  0  end ) 现金量流出

from



  (select  fvoucherid,famount,0  as a   from  t_CashFlowBal  where  fitemid in 

(

SELECT fitemid

FROM t_Item

WHERE (FItemClassID = 9)  and fnumber like 'ci1.01.%'  or fnumber like 'ci2.01.%' or fnumber like 'ci3.01.%'

or fnumber like 'ci4.01')

union all

select  fvoucherid,famount,1  from  t_CashFlowBal  where  fitemid in 

(SELECT fitemid

FROM t_Item

WHERE (FItemClassID = 9)  and fnumber like 'ci1.02.%'  or fnumber like 'ci2.02.%' or fnumber like 'ci3.02.%'

or fnumber like 'ci4.02')) a ) a 

group by a.fvoucherid) a) a

inner join t_voucher b on a.fvoucherid=b.fvoucherid


group by b.fdate,b.fnumber

having sum(a.凭证余额)-sum(a.流量表余额)<>0


图标赞 4
4人点赞
还没有人点赞,快来当第一个点赞的人吧!
图标打赏
0人打赏
还没有人打赏,快来当第一个打赏的人吧!