建工项目对账查询引擎sql

select * from ((select gl_detail.explanation, bd_accsubj.dispname, gl_detail.debitamount 借方, gl_detail.creditamount 贷方, gl_detail.yearv, gl_detail.periodv , gl_voucher.no 凭证号, wmsys.wm_concat(gl_freevalue.valuecode) valuecode, wmsys.wm_concat(gl_freevalue.valuename) valuename from bd_accsubj join gl_detail on gl_detail.pk_accsubj = bd_accsubj.pk_accsubj join bd_glorgbook on bd_glorgbook.pk_glorgbook = bd_accsubj.pk_glorgbook join gl_voucher on gl_detail.pk_voucher = gl_voucher.pk_voucher left join gl_freevalue on gl_detail.assid = gl_freevalue.freevalueid where gl_detail.dr = '0'

   and  gl_detail.yearv>=#byear# and gl_detail.pk_systemv!='TR'

and bd_accsubj.subjcode not in('41040107','41040109','41040207','41040209','41040307','41040308') and bd_glorgbook.glorgbookcode = (select glorgbookcode from bd_glorgbook where  pk_glbook='0001AA10000000004VTQ' and (substr(glorgbookcode,1,6)=(select unitcode from bd_corp where pk_corp=#LoginCorp#)) ) and gl_freevalue.valuecode like #duty# ||'%' 

group by gl_detail.explanation, bd_accsubj.dispname, gl_detail.creditamount, gl_detail.debitamount, gl_detail.yearv, gl_detail.periodv, gl_voucher.no) union (select gl_detail.explanation, bd_accsubj.dispname, gl_detail.debitamount 借方, gl_detail.creditamount 贷方, gl_detail.yearv, gl_detail.periodv , gl_voucher.no 凭证号, wmsys.wm_concat(gl_freevalue.valuecode) valuecode, wmsys.wm_concat(gl_freevalue.valuename) valuename from bd_accsubj join gl_detail on gl_detail.pk_accsubj = bd_accsubj.pk_accsubj join bd_glorgbook on bd_glorgbook.pk_glorgbook = bd_accsubj.pk_glorgbook join gl_voucher on gl_detail.pk_voucher = gl_voucher.pk_voucher left join gl_freevalue on gl_detail.assid = gl_freevalue.freevalueid where gl_detail.dr = '0'

   and  gl_detail.yearv>=#byear# and gl_detail.pk_systemv!='TR'

   and bd_glorgbook.glorgbookcode = (select glorgbookcode from bd_glorgbook where  pk_glbook='0001AA10000000004VTQ' and (substr(glorgbookcode,1,6)=(select unitcode from bd_corp where pk_corp=#LoginCorp#)) ) and ( bd_accsubj.subjcode like '2120'||substr(#accsubj#,-2,2)||'%' 

or ( bd_accsubj.subjcode='5402' and gl_detail.explanation like '%' ||#explain#||'%') ) group by gl_detail.explanation, bd_accsubj.dispname, gl_detail.creditamount, gl_detail.debitamount, gl_detail.yearv, gl_detail.periodv, gl_voucher.no)) order by yearv,periodv,dispname

建工项目对账查询引擎sql

 
  

你可能感兴趣的:(sql)