select
	a.cucd,
	a.cunm,
	a.cuscd,
	a.spnm,
	a.spktcd,
	a.spktnm,
	a.vseq,
	to_char(a.dat1, 'yyyy/mm/dd') as dat1,
	to_char(a.dat2, 'yyyy/mm/dd') as dat2,
	to_char(a.idat, 'yyyy/mm/dd') as idat,
	a.amt,
	sum(a.amt) over ( partition by ktktcd ) as t_amt,
	count(*) over ( partition by ktktcd ) as t_vseq,
	a.ksts,
	null cuiseq,
	null viseq
from af241v01 a
where a.ktktcd=:ktktcd
	and (:cucd is null or a.cucd = :cucd)
	and (:cuscd is null or a.cuscd = :cuscd)
	and (:spktcd is null or a.spktcd = :spktcd)
	and (:dat1s is null or a.dat1>=to_date(:dat1s, 'yyyy/mm/dd'))
	and (:dat1e is null or a.dat1<=to_date(:dat1e, 'yyyy/mm/dd'))
	and (:vseq is null or a.vseq = :vseq)
order by a.cucd,a.cuscd,a.spktcd,a.vseq
