[selectRecords]
select 
	sh.den_no,
	(1+sm.row_no) as row_no,
	to_char(to_date(sh.input_ymd, 'YYYYMMDD'), 'yyyy/mm/dd') as input_ymd,
	to_char(to_date(sh.syori_ymd, 'YYYYMMDD'), 'yyyy/mm/dd') as syori_ymd,
	sh.zeinuki_gaku,
	sh.zei_gaku,
	sh.zeikomi_gaku,
--	sm.hin_cd,
	(case when(mh.jan_cd != '')then(mh.jan_cd)else(sm.hin_cd)end) as hin_cd,
	replace(sm.hin_nm,chr(10),'')as hin_nm,
	sm.suryo,
	sm.tanka,
	sm.kingaku,
	t.sir_cd,
	t.sir_nm,
	t.addr1,
	t.addr2,
	t.addr3,
	t.addr4,
	t.tori_cond,
	t.biko1,
	t.biko2,
	t.biko3,
	t.biko4
from t_sir sh
left join m_sir t on(sh.sir_cd = t.sir_cd)
left join t_sir_m sm on(sh.den_no = sm.den_no)
left join m_hin mh on (mh.hin_cd = sm.hin_cd)
where 1 = 1
and ((sh.syori_ymd >= '&1') or ('&1' = ''))
and ((sh.syori_ymd <= '&2') or ('&2' = ''))
and ((cast(sh.den_no as char(6)) = '&3') or ('&3' = ''))
and ((sh.tok_cd = '&4') or ('&4' = ''))
and ((sm.hin_nm like '%&5%') or ('&5' = ''))
order by sh.den_no,sm.row_no;

