select max(a.viseq) viseq,count(distinct a.viseq) cnt
from axm99 h,aur32 a
	where a.ktktcd=:ktktcd
	and a.cucd=:cucd
	and nvl(a.cuscd,'null')=nvl(:cuscd,'null')
	and a.vseq=:vseq
	and a.dcls='2'
	and a.nbil=0
	and a.sts=0
	and a.ktktcd=h.ktktcd
	and ((:sts='3') or (:sts<>'3' and a.sbat2>=h.sbat2))	/* 2008.02.05 se-322 請求訂正の考慮を追加 */
	and (a.sbat>=:sbat or a.sbat=-999)