select max(cuiseq) cuiseq,count(distinct cuiseq) cnt
    from afr3123
    where cls='23'                                        /*未確定*/             /*当日確定分*/
        and (:pmode = 'get' and cls1 in ('0','1') and ((sts in ('0','1')) or (sts in ('2','3') and sdat=to_date(:sdday,'yyyy/mm/dd'))) or /*表示時はEOSも可。未チェック修正・チェック済み表示が可。当日確定はplsqlでメッセージを取得するためここでは許容*/
            (:pmode = 'ref' and cls1='0' and sts is not null)) 
        and ktktcd=:ktktcd and cucd=:cucd and cuscd=:cuscd
        and vseq=:vseq
