[load_grdList]
select
  w.den_no
, w.row_no
, w.syori_ymd
, w.ns_kbn_cd
, w.ns_kbn
, w.biko1
, w.hin_cd
, w.hin_nm
, w.suryo
, w.kakutei_flg
, w.jan_cd
, w.mst_hin_nm
, w.mst_hin_rnm
, w.biko2
from (

select
  th.den_no
, tm.row_no
, th.syori_ymd
, th.ns_kbn as ns_kbn_cd
, h1.han_name as ns_kbn
, th.biko1
, tm.hin_cd
, tm.hin_nm
, tm.suryo
, tm.kakutei_flg
, m.jan_cd
, m.hin_nm as mst_hin_nm
, m.hin_rnm as mst_hin_rnm
, th.biko2
from t_nyusyuko th
inner join t_nyuko tm on (tm.den_no = th.den_no)
inner join m_hin m on (m.hin_cd = tm.hin_cd)
left join m_hanyo h1 on (h1.mst_kbn = '25' and h1.han_cd = th.ns_kbn)
where th.del_flg = 0
union all
select
  th.den_no
, tm.row_no
, th.syori_ymd
, th.ns_kbn as ns_kbn_cd
, h1.han_name as ns_kbn
, th.biko1
, tm.hin_cd
, tm.hin_nm
, tm.suryo
, tm.kakutei_flg
, m.jan_cd
, m.hin_nm as mst_hin_nm
, m.hin_rnm as mst_hin_rnm
, th.biko2
from t_nyusyuko th
inner join t_syuko tm on (tm.den_no = th.den_no)
inner join m_hin m on (m.hin_cd = tm.hin_cd)
left join m_hanyo h1 on (h1.mst_kbn = '25' and h1.han_cd = th.ns_kbn)
where th.del_flg = 0
union all
select
  th.den_no
, tm.row_no
, th.syori_ymd
, th.ns_kbn as ns_kbn_cd
, h1.han_name as ns_kbn
, th.biko1
, tm.old_hin_cd as hin_cd
, tm.old_hin_nm as hin_nm
, -tm.suryo as suryo
, tm.kakutei_flg
, m.jan_cd
, m.hin_nm as mst_hin_nm
, m.hin_rnm as mst_hin_rnm
, th.biko2
from t_nyusyuko th
inner join t_ido tm on (tm.den_no = th.den_no)
inner join m_hin m on (m.hin_cd = tm.old_hin_cd)
left join m_hanyo h1 on (h1.mst_kbn = '25' and h1.han_cd = th.ns_kbn)
where th.del_flg = 0
union all
select
  th.den_no
, tm.row_no
, th.syori_ymd
, th.ns_kbn as ns_kbn_cd
, h1.han_name as ns_kbn
, th.biko1
, tm.new_hin_cd as hin_cd
, tm.new_hin_nm as hin_nm
, +tm.suryo as suryo
, tm.kakutei_flg
, m.jan_cd
, m.hin_nm as mst_hin_nm
, m.hin_rnm as mst_hin_rnm
, th.biko2
from t_nyusyuko th
inner join t_ido tm on (tm.den_no = th.den_no)
inner join m_hin m on (m.hin_cd = tm.new_hin_cd)
left join m_hanyo h1 on (h1.mst_kbn = '25' and h1.han_cd = th.ns_kbn)
where th.del_flg = 0

) w
where 1 = 1
and ((w.den_no = fnc_to_number(':den_no')) or ('' = ':den_no'))
and (('' = ':syori_ymd_fr') or (w.syori_ymd >= ':syori_ymd_fr'))
and (('' = ':syori_ymd_to') or (w.syori_ymd <= ':syori_ymd_to'))
and ((w.ns_kbn_cd = ':ns_kbn') or (':ns_kbn' = ''))
and ((w.jan_cd LIKE '%:jan_cd' or w.jan_cd LIKE '%:jan_cd /%') or (':jan_cd' = ''))
and ((w.hin_cd LIKE '%:hin_cd' or w.jan_cd LIKE '%:hin_cd' or w.jan_cd LIKE '%:hin_cd /%') or (':hin_cd' = ''))
and ((w.mst_hin_nm LIKE '%:hin_nm%' or w.mst_hin_rnm LIKE '%:hin_nm%') or (':hin_nm' = ''))
and ((w.biko1 like '%:biko1%' or w.biko2 like '%:biko1%') or ('' = ':biko1'))
and ((':nk_cond' != '0') or (w.kakutei_flg = 0))
and ((':nk_cond' != '1') or (w.kakutei_flg = 1))

order by syori_ymd desc, den_no desc, row_no




