select
	a.viseq,
	a.cucd,
	a.cunm,
	a.cuscd,
	a.spnm,
	to_char(a.adat, 'yyyy/mm/dd') as adat,
	a.vseq,
	a.amt,
	count(distinct a.vseq) over ( partition by ktktcd ) as t_vseq,
	sum(amt) over ( partition by ktktcd ) as t_amt
from af265v01 a
where a.ktktcd=:ktktcd
	and (:adats is null or a.adat>=to_date(:adats, 'yyyy/mm/dd'))
	and (:adate is null or a.adat<=to_date(:adate, 'yyyy/mm/dd'))
	and (:cucd is null or a.cucd = :cucd)
	and (:cuscd is null or a.cuscd = :cuscd)
	and (:vseq is null or a.vseq = :vseq)
	and Chk_Sbat(1,ktktcd,cucd,cuscd,sbat,sbat2,cuclcls)=0
order by a.cucd,a.cuscd,a.adat,a.vseq
