select max(a.viseq) as viseq,
  count(distinct a.viseq) as cnt
from axm99 b,aur32 a
where a.ktktcd=:ktktcd
  and a.vseq=:vseq
  and a.cucd=:cucd
  and ( (:cuscd is null and a.cuscd is null) or (:cuscd is not null and a.cuscd=:cuscd ) )
  and a.dcls='1' and a.tcls=:tcls
  and a.sts=0
  and a.ktktcd=b.ktktcd
  and ((:sts='3') or (:sts<>'3' and a.sbat2>=b.sbat2))
  and (a.sbat>=:sbat or a.sbat=-999)
  and (:viseq is null or a.viseq = :viseq)
