[loadOriginal]
--select fnc_load_basv1015(:s_id, :den_no)

[updateOriginal]
select fnc_update_basv1015()

[load_grdList_nm]
select mst_kbn, right(han_cd,3) as han_cd, han_name, koumoku1, koumoku2
 ,han_cd as hin_cd
--from w_hin_nm
from m_hanyo
where mst_kbn = '05'
and koumoku1 = ':cat_cd'
and ((upper(han_name) like upper('%:hin_nm%')) or ('' = ':hin_nm'))
order by han_cd
;


[load_grdList_maker]
select mst_kbn, right(han_cd,3) as han_cd, han_name, koumoku1, koumoku2, koumoku8
 ,han_cd as hin_cd
--from w_maker
from m_hanyo
where mst_kbn = '06'
and koumoku1 = ':cat_cd:hin_sts'
and ((upper(han_name) like upper('%:maker_nm%')) or ('' = ':maker_nm'))
order by han_cd
;

[load_grdList]
select
right(hn.hin_cd,3) as hin_cd
, hn.hin_nm
, hn.hin_sts
, hn.cat_cd
, hn.brand_cd
, han1.han_name as tani_nm
, hn.del_flg
, hn.cre_time
, hn.upd_time
, hn.stop_flg
, hn.stanka
, hn.biko1
, hn.biko2
, hn.tani
, hn.inner_flg
, hn.non_stock_flg
, han_cd as han_cd
from m_hin hn
left join m_hanyo han1 on (hn.tani = han1.han_cd and han1.mst_kbn = '44')
where 1 = 1
--and ((hn.hin_cd like '%:hin_cd%') or ('' = ':hin_cd'))
--and ((hn.hin_nm like '%:hin_nm%') or ('' = ':hin_nm'))
and (('' = ':cat_cd') or (hn.cat_cd = ':cat_cd'))
and (('' = ':cat_cd:hin_sts') or (hn.hin_sts = ':cat_cd:hin_sts'))
and (('' = ':cat_cd:hin_sts:brand_cd') or (hn.brand_cd = ':cat_cd:hin_sts:brand_cd'))
--and ((substr(hn.hin_cd,4,3) = ':hin_sts') or ('' = ':hin_sts')) or (hn.hin_sts = ':hin_sts')
--and (('' = case when hn.hin_sts = '' then '' else ':cat_cd' ||':hin_sts' end ) or (hn.hin_sts = case when hn.hin_sts = '' then '' else ':cat_cd' ||':hin_sts'end ))
--and (('' = ':brand_cd') or (brand_cd = ':brand_cd'))
order by hn.hin_cd

[getNextName]
--select koumoku1 || lpad((coalesce(max(koumoku2)::numeric,0) + 1)::text, 3, '0') as new_id
select lpad((coalesce(max(koumoku1)::numeric,0) + 1)::text, 3, '0') as new_id
from m_hanyo
where mst_kbn = '05'
and koumoku1 = ':cat_cd'
--group by mst_kbn,koumoku1
;

[getNextMaker]
select lpad((coalesce(max(koumoku2)::numeric,0) + 1)::text, 3, '0') as new_id
from m_hanyo
where mst_kbn = '06'
and koumoku1 = ':hin_sts'
--group by mst_kbn,koumoku2
;

[getNextHin]
--select lpad((coalesce(max(hin_cd)::numeric,0) + 1)::text, 12, '0') as new_id
select ':brand_cd' || right(lpad((coalesce(max(hin_cd)::numeric,0) + 1)::text, 12, '0'),3) as new_id
from m_hin
where brand_cd = ':brand_cd'
;

[chk_grdList_nm]
select han_cd, han_name, koumoku1, koumoku2
from m_hanyo
where mst_kbn = '05'
and koumoku1 = ':cat_cd'
and koumoku2 = ':now_value'
;

[chk_grdList_maker]
select mst_kbn, han_cd, han_name, koumoku1, koumoku2, koumoku8
--from w_maker
from m_hanyo
where mst_kbn = '06'
and koumoku1 = ':hin_sts'
and koumoku2 = ':now_value'
;

[chk_grdList]
select
hn.hin_cd
, hn.hin_nm
, hn.hin_sts
, hn.cat_cd
, hn.brand_cd
, han1.han_name as tani_nm
, hn.del_flg
, hn.cre_time
, hn.upd_time
, hn.stop_flg
, hn.stanka
, hn.biko1
, hn.biko2
, hn.tani
, hn.inner_flg
, hn.non_stock_flg
from m_hin hn
left join m_hanyo han1 on (hn.tani = han1.han_cd and han1.mst_kbn = '44')
where 1 = 1
and (hn.cat_cd = ':cat_cd')
and (hn.hin_sts = ':hin_sts')
and (hn.brand_cd = ':brand_cd')
and (right(hn.hin_cd, 3) = ':now_value')


[load_grdList_nm_log]
select mst_kbn, han_cd, han_name, koumoku1, koumoku2
--from w_hin_nm
from m_hanyo
where mst_kbn = '05'
and koumoku1 = ':cat_cd'
and ((upper(han_name) like upper('%:hin_nm%')) or ('' = ':hin_nm'))
order by han_cd
;

[load_grdList_maker_log]
select mst_kbn, han_cd, han_name, koumoku1, koumoku2, koumoku8
--from w_maker
from m_hanyo
where mst_kbn = '06'
and koumoku1 = ':hin_sts'
and ((upper(han_name) like upper('%:maker_nm%')) or ('' = ':maker_nm'))
order by han_cd
;

[load_grdList_log]
select
hn.hin_cd
, hn.hin_nm
, hn.hin_sts
, hn.cat_cd
, hn.brand_cd
, han1.han_name as tani_nm
, hn.del_flg
, hn.cre_time
, hn.upd_time
, hn.stop_flg
, hn.stanka
, hn.biko1
, hn.biko2
, hn.tani
, hn.inner_flg
, hn.non_stock_flg
from m_hin hn
left join m_hanyo han1 on (hn.tani = han1.han_cd and han1.mst_kbn = '44')
where 1 = 1
--and ((hn.hin_cd like '%:hin_cd%') or ('' = ':hin_cd'))
--and ((hn.hin_nm like '%:hin_nm%') or ('' = ':hin_nm'))
and (('' = ':cat_cd') or (hn.cat_cd = ':cat_cd'))
and (('' = ':hin_sts') or (hn.hin_sts = ':hin_sts'))
and (('' = ':brand_cd') or (hn.brand_cd = ':brand_cd'))
--and ((substr(hn.hin_cd,4,3) = ':hin_sts') or ('' = ':hin_sts')) or (hn.hin_sts = ':hin_sts')
--and (('' = case when hn.hin_sts = '' then '' else ':cat_cd' ||':hin_sts' end ) or (hn.hin_sts = case when hn.hin_sts = '' then '' else ':cat_cd' ||':hin_sts'end ))
--and (('' = ':brand_cd') or (brand_cd = ':brand_cd'))
order by hn.hin_cd