[selectRecords] select '1' as kbn, case t.cat_cd when '1' then case uh.tok_tan when '' then '御中' else '' end when '2' then '様' else '御中' end as keisyou, case uh.tok_tan when '' then '' else '様' end as keisyou2, uh.den_no, (1+um.row_no) as row_no, trunc((row_no)/6) as row_page, (trunc((row_no)/6)+1) as page1, sm2.pege_m, (trunc((row_no)/6)+1)||'/'||sm2.pege_m as page_c, to_char(to_date(uh.input_ymd, 'YYYYMMDD'), 'yyyy/mm/dd') as input_ymd, case uh.syori_ymd when '' then '' else to_char(to_date(uh.syori_ymd, 'YYYYMMDD'), 'yyyy/mm/dd') end as syori_ymd, uh.tok_tan, replace(replace(uh.biko1,chr(13)||chr(10),chr(10)),chr(10),chr(13)||chr(10)) as u_biko1, replace(replace(uh.biko2,chr(13)||chr(10),chr(10)),chr(10),chr(13)||chr(10)) as u_biko2, um.hin_cd, replace(um.hin_nm,chr(10),'')as hin_nm, um.tok_hacyu_no, case uh.jucyu_flg when '0' then um.kei_suryo else um.kei_jucyu_su end as suryo, um.tanka, um.kingaku, --原価、粗利 STT um.genka_gaku, (case when(um.jucyu_su != 0)then(round(um.genka_gaku / um.jucyu_su, 2))else(null)end) as gentanka, um.kingaku - um.genka_gaku as arari, --原価、粗利 END case um.nonyu_ymd when '' then '' else to_char(to_date(um.nonyu_ymd, 'YYYYMMDD'), 'yyyy/mm/dd') end as nonyu_ymd, uh.tok_cd, uh.nonyu_nm as n_tok_nm, uh.tok_nm, (case t.zip_no when '' then '' else left(t.zip_no,3)||'-'||right(t.zip_no,4) end) as yubin_no, (case uh.nonyu_zip_no when '' then '' else left(uh.nonyu_zip_no,3)||'-'||right(uh.nonyu_zip_no,4) end) as n_yubin_no, coalesce(cast(um.jucyu_no as varchar(10)),'')||'-'|| coalesce (cast(um.row_no as varchar(10)),'') as jucyu_row_no, t.addr1, t.addr2, t.addr3, t.addr4, coalesce(t.addr3,'')||coalesce(t.addr4,'') as addr3_4, t.tori_cond, t.biko1, t.biko2, t.biko3, t.biko4, uh.nonyu_tel_no as n_tel_no, t.tel_no as tel_no, t.fax_no as fax_no, uh.nonyu_nm, (case uh.nonyu_zip_no when '' then '' else left(uh.nonyu_zip_no,3)||'-'||right(uh.nonyu_zip_no,4) end) as nonyu_yubin_no, uh.nonyu_addr1, uh.nonyu_addr2, uh.nonyu_addr3, uh.nonyu_addr4, uh.nonyu_tan, uh.nonyu_tel_no, uh.nonyu_fax_no, tan.tan_nm, coalesce(t.cat_cd,'1') as tok_dm, h.tani as tan, h.bante as bante, um.tani_suryo as havy, um.jucyu_su, um.bante as bante, um.htanka as teika, um.meisai_biko as biko_m , j.mst_kbn , j.han_cd , j.han_name , j.koumoku1 , j.koumoku2 , j.koumoku3 , j.koumoku4 , j.koumoku5 , j.koumoku6 , j.koumoku7 , j.koumoku8 , j.koumoku9 , stan1.tan_rnm as tan1 , tm1.kousu as k1 , stan2.tan_rnm as tan2 , tm2.kousu as k2 , stan3.tan_rnm as tan3 , tm3.kousu as k3 , stan4.tan_rnm as tan4 , tm4.kousu as k4 , stan5.tan_rnm as tan5 , tm5.kousu as k5 , stan6.tan_rnm as tan6 , tm6.kousu as k6 , stan7.tan_rnm as tan7 , tm7.kousu as k7 , stan8.tan_rnm as tan8 , tm8.kousu as k8 , stan9.tan_rnm as tan9 , tm9.kousu as k9 , stan10.tan_rnm as tan10 , tm10.kousu as k10 ,uh.zeinuki_gaku ,uh.zei_gaku ,uh.zeikomi_gaku ,f1.han_name as pay_kbn ,f2.han_name as haiso_kbn ,f3.han_name as konpo_keijyo ,case uh.nyukin_yotei_ymd when '' then '' else to_char(to_date(uh.nyukin_yotei_ymd, 'YYYYMMDD'), 'yyyy/mm/dd') end as nyukin_yotei_ymd /*,uh.pay_kbn as pay_kbn ,uh.haiso_kbn as haiso_kbn ,uh.konpo_keijyo as konpo_keijyo ,uh.nyukin_yotei_ymd as nyukin_yotei_ymd*/ from t_uri uh left join m_tanto tan on(uh.tan_cd = tan.tan_cd) left join m_tokui t on(uh.tok_cd = t.tok_cd) left join t_uri_m um on(uh.den_no = um.den_no) left join m_hin h on(um.hin_cd = h.hin_cd) left join m_hanyo j on (j.mst_kbn='90' and j.han_cd='jisya') left join (select um2.den_no,max(trunc((row_no)/6)+1) as pege_m from t_uri_m um2 group by um2.den_no) sm2 on sm2.den_no = uh.den_no left join t_seizou ts on(uh.den_no = ts.jucyu_no and ts.shiji_no = (um.row_no + 100 * uh.den_no)) left join t_seizou_m tm1 on(ts.shiji_no = tm1.shiji_no and tm1.koutei_no = 0) left join t_seizou_m tm2 on(ts.shiji_no = tm2.shiji_no and tm2.koutei_no = 1) left join t_seizou_m tm3 on(ts.shiji_no = tm3.shiji_no and tm3.koutei_no = 2) left join t_seizou_m tm4 on(ts.shiji_no = tm4.shiji_no and tm4.koutei_no = 3) left join t_seizou_m tm5 on(ts.shiji_no = tm5.shiji_no and tm5.koutei_no = 4) left join t_seizou_m tm6 on(ts.shiji_no = tm6.shiji_no and tm6.koutei_no = 5) left join t_seizou_m tm7 on(ts.shiji_no = tm7.shiji_no and tm7.koutei_no = 6) left join t_seizou_m tm8 on(ts.shiji_no = tm8.shiji_no and tm8.koutei_no = 7) left join t_seizou_m tm9 on(ts.shiji_no = tm9.shiji_no and tm9.koutei_no = 8) left join t_seizou_m tm10 on(ts.shiji_no = tm10.shiji_no and tm10.koutei_no = 9) left join m_tanto stan1 on(tm1.seizou_tan_cd = stan1.tan_cd) left join m_tanto stan2 on(tm2.seizou_tan_cd = stan2.tan_cd) left join m_tanto stan3 on(tm3.seizou_tan_cd = stan3.tan_cd) left join m_tanto stan4 on(tm4.seizou_tan_cd = stan4.tan_cd) left join m_tanto stan5 on(tm5.seizou_tan_cd = stan5.tan_cd) left join m_tanto stan6 on(tm6.seizou_tan_cd = stan6.tan_cd) left join m_tanto stan7 on(tm7.seizou_tan_cd = stan7.tan_cd) left join m_tanto stan8 on(tm8.seizou_tan_cd = stan8.tan_cd) left join m_tanto stan9 on(tm9.seizou_tan_cd = stan9.tan_cd) left join m_tanto stan10 on(tm10.seizou_tan_cd = stan10.tan_cd) left join m_hanyo f1 on (f1.mst_kbn = '76' and uh.pay_kbn = f1.han_cd) left join m_hanyo f2 on (f2.mst_kbn = '77' and uh.haiso_kbn = f2.han_cd) left join m_hanyo f3 on (f3.mst_kbn = '42' and uh.konpo_keijyo = f3.han_cd) where 1 = 1 and uh.jucyu_flg = 1 and uh.del_flg = 0 and ((uh.syori_ymd >= '&1') or ('&1' = '')) and ((uh.syori_ymd <= '&2') or ('&2' = '')) and ((cast(uh.den_no as char(6)) = '&3') or ('&3' = '')) and ((uh.tok_cd = '&4') or ('&4' = '')) and ((um.hin_nm like '%&5%') or ('&5' = '')) order by den_no,kbn,row_no;