select    m03.cunm,m032.spnm,
          a.wseq,a.ktktcd,a.cucd,a.cuscd,a.vseq,
          a.cuslip1,a.gdflg,
          to_char(a.jdat,'yyyy/mm/dd') jdat,
          to_char(a.ydat,'yyyy/mm/dd') ydat,
          to_char(a.climit,'yyyy/mm/dd') climit,
          a.spktcd,b.ktktnm spktnm,
          a.cudcd,c.cshnm cudnm,
          a.dcubcd,a.cuslip2,a.bbno,a.com,
          decode(a.jmcat,'3','1',a.jmcat) jmcat, /*'3'は通常扱い*/
          a.jmcat jmcat2, /*jmcat='1'or'3'は明細毎に設定可*/
          decode(a.jmcat,'3','checked',null) chkjmcat,
          a.dtxt1,a.dtxt2,a.ltxt1,a.ltxt2,
          a.iseq,a.iseq80,a.vlin,a.jan,a.ijan,a.gdjnm,a.gdjstnd,
          a.gdcnum,a.gdbnum,a.gdstun,a.gdcls9,f.scls5 gdcls9nm,
          a.mvpno,a.cst,a.sal,a.gdcst,
          calc_amt(a.cucd,a.mvpno,a.cst,a.ktktcd) scst,
          nvl(a.mvpno,0)*nvl(a.sal,0) ssal,
          g.gdcls7,
          d.chgnm chgnm,
          to_char(a.idat,'yyyy/mm/dd hh24:mi:ss') idat,
          e.chgnm upchgnm,
          case when a.udat=a.idat then null else to_char(a.udat,'yyyy/mm/dd hh24:mi:ss') end udat,
          a.pkbn1,a.pkbn2,a.hflg,
          g.undkbn
     from afm032 m032, afm03 m03, afm02 g,afm90 f,afm08 e,afm08 d,afm036 c,afm05 b,afw80 a
     where a.wseq=:wseq and a.cls='0'
          and a.cucd=:cucd and a.cuscd=:cuscd
          and nvl(a.dflg,0)<>1
          and a.spktcd=b.ktktcd(+)
          and a.cucd=c.cucd(+) and a.cudcd=c.cshcd(+)
          and a.chgcd=d.chgcd(+)
          and a.upchg=e.chgcd(+)
          and f.cls(+)='6' and a.gdcls9=f.scls1(+)
          and a.ijan=g.ijan(+)
          and a.cucd = m03.cucd(+)
          and a.cucd = m032.cucd(+) and a.cuscd = m032.cuscd(+)
     order by a.vlin