select
	a.cuiseq,
	a.vseq,
	a.vlin,
	a.spktcd2,
	a.spktnm2,
	a.jan,
	a.gdcls9nm,
	a.gdjnm,
	a.gdjstnd,
	a.mvpno,
	to_char(a.idat,'yyyy/mm/dd') idat,
	a.spktcd1,
	a.spktnm1,
	to_char(a.vdat,'yyyy/mm/dd') vdat
from af251v01 a
where a.ktktcd=:ktktcd
  and (:vdat is null or a.vdat=to_date(:vdat,'yyyy/mm/dd'))
  and (:spktcd1 is null or a.spktcd1=:spktcd1)
  and (:spktcd2 is null or a.spktcd2=:spktcd2)
  and (:jan is null or a.jan=:jan)
  and (:vseq is null or a.vseq=:vseq) /*表示前チェックで複数伝票あった時*/
order by a.vseq,a.vlin,a.spktcd1,a.spktcd2