insert into afw53 (
	dnpc,denp,npar2,cpar1,cpar3,cpar4,
	cpar5,cpar6,cpar7,cpar8,cpar9,cpar10,dpar1
)
select '25', '253', :prno, :parea, :h_pkbn1, :h_pkbn2,
	:term, :cudenp, :ktktcd, :ipadr, a.viseq, :ktktcd,sysdate
from (
	select distinct a.vseq,a.viseq from axm99 d,afr3123 c,afm03 b,aur32 a
		where a.ktktcd=:ktktcd and a.dcls='1'
			and a.tcls=:tcls and a.psts=:psts
			and a.cucd=:cucd and a.cuscd=:cuscd
			and (:h_chgcd is null or a.chgcd=:h_chgcd)
			and (:h_sadat is null or a.adat>=to_date(:h_sadat,'yyyy/mm/dd'))
			and (:h_eadat is null or a.adat<=to_date(:h_eadat,'yyyy/mm/dd'))
			and ((:hvseq=0 and a.hvseq is null) or (:hvseq=1 and a.hvseq is not null))
			and a.cucd=b.cucd
			and a.piseq=c.iseq(+)
			and decode(nvl(c.cls1,'0'),'1',nvl(b.cudenp1,b.cudenp2),b.cudenp2)=:cudenp
			and a.ktktcd=d.ktktcd
			and (a.psts=0 or (a.psts=-1 and a.adat>=add_months(d.sdday,-2)))
		order by a.vseq,a.viseq
) a
