select
  a.iseq30,
  a.viseq,
  to_char(a.adat, 'yyyy/mm/dd') as adat,
  to_char(a.adat, 'yyyy/mm/dd') as orgadat,
  a.vseq,
  a.vlin, a.vlin as orgvlin,
  a.tcls, a.tcls as orgtcls,
  a.amt, a.amt as orgamt,
  a.txt2, a.txt2 as orgtxt2,
  e.chgnm chgcdnm,
  to_char(a.idat, 'yyyy/mm/dd hh24:mi:ss') as idat,
  f.chgnm upchgnm,
  decode(a.tcls,'81','現金','82','手形','85','小切手','86','振込','83','相殺') tclsnm,
  case when a.udat=a.idat then null else to_char(a.udat, 'yyyy/mm/dd hh24:mi:ss') end udat
from axm99 h,afm08 f,afm08 e,aur32 a
where a.ktktcd=:ktktcd
  and a.mcd=:mcd
  and a.vseq=:vseq
  and a.dcls='4'
  and a.sts=0
  and a.viseq=:viseq
  and a.ktktcd=h.ktktcd
  and a.sbat2>=h.ssbat2
  and a.chgcd=e.chgcd(+)
  and a.upchg=f.chgcd(+)
order by a.vlin
