[selectRecords] select '請求一覧表' as report_nm, (trunc(row_number() over (order by tok_cd)/ 25) +1) as uri_row_kai, 'Page.'||(trunc(row_number() over (order by tok_cd)/ 25) +1) as uri_row_kai_s, (case when (coalesce(tok_nm,'') != '') then tok_nm||'('||tok_cd||')'else ''end) as tok_nm_s, (case when(seikyu_ymd != '')then(to_char(to_date(seikyu_ymd, 'YYYYMMDD'), 'yyyy/mm/dd'))else('')end) as seikyu_ymd, (case when(nyukin_yotei_ymd != '')then(to_char(to_date(nyukin_yotei_ymd, 'YYYYMMDD'), 'yyyy/mm/dd'))else('')end) as nyukin_yotei_ymd, (case when(nyukinbi != '')then(to_char(to_date(nyukinbi, 'YYYYMMDD'), 'yyyy/mm/dd'))else('')end) as nyukinbi, (case when(mankibi != '')then(to_char(to_date(mankibi, 'YYYYMMDD'), 'yyyy/mm/dd'))else('')end) as mankibi, -- substr('&16',1,4)||'年'||substr('&16',5,2)||'月' as syori_ym_s, '&18'||'年'||'&19'||'月分売掛表' as syori_ym_s, coalesce(furikomi,0) as furikomi, coalesce(genkin,0) as genkin, coalesce(kogitte,0) as kogitte, coalesce(tegata,0) as tegata, coalesce(sousai,0) as sousai, coalesce(tesuryo,0) + coalesce(tesuryo_add,0) as tesuryo, coalesce(sonota,0) + coalesce(sonota_add,0) as sonota, w.* from( select v.tok_cd as tok_cd, v.seikyu_ymd, v.zen_seikyu_zan as zen_seikyu_zan, v.nyukin_gaku as nyukin_gaku, v.kurikoshi_gaku as kurikoshi_gaku, v.zeinuki_gaku as zeinuki_gaku, v.zei_gaku as zei_gaku, v.zeikomi_gaku as zeikomi_gaku, v.seikyu_zan as seikyu_zan, v.nyukin_yotei_ymd, mt.tok_nm as tok_nm, mt.shime_dd, mt.pay_m, mt.pay_d, mt.biko1, mt.tan_cd, mt.tori_cond, mt.zei_calc_kbn, mt.keisyo, mt.tok_rnm, (select max(n.nyukin_ymd) from t_nyu_keshi k inner join t_nyukin n on (n.nyukin_no = k.nyukin_no) where 1=1 and k.tok_cd = v.tok_cd and k.seikyu_ymd = v.seikyu_ymd ) as nyukinbi, -- (select sum(k.nyukin_gaku) (select sum(n.nyukin_gaku) from t_nyu_keshi k inner join t_nyukin n on (n.nyukin_no = k.nyukin_no) inner join m_hanyo h1 on (h1.mst_kbn = '13' and h1.han_cd = n.nyukin_kbn) where 1=1 and k.tok_cd = v.tok_cd and k.seikyu_ymd = v.seikyu_ymd and h1.koumoku1 = 'furikomi' ) as furikomi, -- (select sum(k.nyukin_gaku) (select sum(n.nyukin_gaku) from t_nyu_keshi k inner join t_nyukin n on (n.nyukin_no = k.nyukin_no) inner join m_hanyo h1 on (h1.mst_kbn = '13' and h1.han_cd = n.nyukin_kbn) where 1=1 and k.tok_cd = v.tok_cd and k.seikyu_ymd = v.seikyu_ymd and h1.koumoku1 = 'genkin' ) as genkin, -- (select sum(k.nyukin_gaku) (select sum(n.nyukin_gaku) from t_nyu_keshi k inner join t_nyukin n on (n.nyukin_no = k.nyukin_no) inner join m_hanyo h1 on (h1.mst_kbn = '13' and h1.han_cd = n.nyukin_kbn) where 1=1 and k.tok_cd = v.tok_cd and k.seikyu_ymd = v.seikyu_ymd and h1.koumoku1 = 'kogitte' ) as kogitte, -- (select sum(k.nyukin_gaku) (select sum(n.nyukin_gaku) from t_nyu_keshi k inner join t_nyukin n on (n.nyukin_no = k.nyukin_no) inner join m_hanyo h1 on (h1.mst_kbn = '13' and h1.han_cd = n.nyukin_kbn) where 1=1 and k.tok_cd = v.tok_cd and k.seikyu_ymd = v.seikyu_ymd and h1.koumoku1 = 'tegata' ) as tegata, (select max(n.tegata_ymd) from t_nyu_keshi k inner join t_nyukin n on (n.nyukin_no = k.nyukin_no) where 1=1 and k.tok_cd = v.tok_cd and k.seikyu_ymd = v.seikyu_ymd ) as mankibi, -- (select sum(k.nyukin_gaku) (select sum(n.nyukin_gaku) from t_nyu_keshi k inner join t_nyukin n on (n.nyukin_no = k.nyukin_no) inner join m_hanyo h1 on (h1.mst_kbn = '13' and h1.han_cd = n.nyukin_kbn) where 1=1 and k.tok_cd = v.tok_cd and k.seikyu_ymd = v.seikyu_ymd and h1.koumoku1 = 'sousai' ) as sousai, -- (select sum(k.nyukin_gaku) (select sum(n.total_gaku) from t_nyu_keshi k inner join t_nyukin n on (n.nyukin_no = k.nyukin_no) inner join m_hanyo h1 on (h1.mst_kbn = '13' and h1.han_cd = n.nyukin_kbn) where 1=1 and k.tok_cd = v.tok_cd and k.seikyu_ymd = v.seikyu_ymd and h1.koumoku1 = 'tesuryo' ) as tesuryo, (select sum(n.tesuryo) from t_nyu_keshi k inner join t_nyukin n on (n.nyukin_no = k.nyukin_no) inner join m_hanyo h1 on (h1.mst_kbn = '13' and h1.han_cd = n.nyukin_kbn) where 1=1 and k.tok_cd = v.tok_cd and k.seikyu_ymd = v.seikyu_ymd and COALESCE(h1.koumoku1,'') not in ('tesuryo', '') ) as tesuryo_add, -- (select sum(k.nyukin_gaku) (select sum(n.total_gaku) from t_nyu_keshi k inner join t_nyukin n on (n.nyukin_no = k.nyukin_no) left join m_hanyo h1 on (h1.mst_kbn = '13' and h1.han_cd = n.nyukin_kbn) where 1=1 and k.tok_cd = v.tok_cd and k.seikyu_ymd = v.seikyu_ymd and COALESCE(h1.koumoku1,'') = '' ) as sonota, (select sum(n.cyosei_gaku) from t_nyu_keshi k inner join t_nyukin n on (n.nyukin_no = k.nyukin_no) inner join m_hanyo h1 on (h1.mst_kbn = '13' and h1.han_cd = n.nyukin_kbn) where 1=1 and k.tok_cd = v.tok_cd and k.seikyu_ymd = v.seikyu_ymd and COALESCE(h1.koumoku1,'') not in ('tesuryo', '') ) as sonota_add, '' as biko_a from t_urikake v inner join m_tokui mt on (v.tok_cd = mt.tok_cd) left join m_tanto tn on (tn.tan_cd = mt.tan_cd) where 1=1 and v.del_flg= 0 and v.zeinuki_gaku <> 0 -- and (('' = '&16') or (v.seikyu_ymd >= '&16')) and (('' = '&17') or (v.seikyu_ymd <= '&17')) and (('' = '&2') or (tn.bu_cd = '&2')) and (('' = '&4') or (mt.cat_cd = '&4')) --and (('1' = '&30') or (v.seikyu_zan > 0)) and (('' = '&24') or (tn.tan_cd >= '&24')) and (('' = '&25') or (tn.tan_cd <= '&25')) and (('' = '&20') or (mt.tok_cd >= '&20')) and (('' = '&21') or (mt.tok_cd <= '&21')) -- and (('' = '&16') or (substr(v.seikyu_ymd,1,6) = substr('&16',1,6))) and (('' = ('&18'||'&19')) or (substr(v.seikyu_ymd,1,6) =('&18'||'&19'))) )w order by w.tok_cd,uri_row_kai