[existKey]
select 1 from m_hin
where hin_cd = ':hin_cd'

[load_grdList_rireki]
select
  syori_ymd
, tor_cd
, tor_nm
, tanka
, tanka_f2
, den_no
, row_no
, tor_kbn
, nyuko_su
, syuko_su
, tor_kbn_key
from v_hin_rireki
where hin_cd = ':hin_cd'
and ((':ns_cond' != 'n') or (tor_kbn_key in ('01', '02', '03')))
and ((':ns_cond' != 's') or (tor_kbn_key in ('04', '05', '06')))
order by syori_ymd desc,tor_kbn desc,den_no desc,row_no

[changeHin]
select fnc_update_change_hin(':hin_cd', ':nhin_cd', ':login_id');

[existNewKey]
select 1 from m_hin
where hin_cd = ':nhin_cd'


[mhin_auto]
select coalesce(oya.han_cd, '') as group_cd, oya.koumoku1 as mhin_auto
from m_hanyo ko --on hin.cat_cd = ko.han_cd
inner join m_hanyo oya on ko.koumoku1 = oya.han_cd and oya.mst_kbn = '14'
where ko.mst_kbn = '05' 
and ko.han_cd = ':ocat_cd'
--and ko.koumoku2 = ':ocat_cd'
;

[get_new_cd]
select max(hin.hin_cd) as max_cd
from m_hin hin
inner join m_hanyo ko on ko.koumoku2 = hin.cat_cd and ko.mst_kbn = '05'
--where ko.koumoku2 = ':group_cd'
where ko.koumoku1 = ':group_cd'
and hin_cd ~ '^[0-9]+$'
;

[load_grdList_sir]
select
	hs.hin_cd
	, hs.sir_cd
	, ms.sir_nm
	, hs.row_no
	, hs.sir_hin_cd
	, hs.sir_hin_nm
	, hs.tanka
	, hs.tanka as tanka_f2
	, hs.biko
	, hs.del_flg
	, hs.cre_id
	, hs.cre_time
	, hs.upd_id
	, hs.upd_time
from m_sirhin hs
left join m_sir ms on (ms.sir_cd = hs.sir_cd) 
where hin_cd = ':hin_cd'
order by hs.sir_cd,hs.row_no;

--update m_hinsir
--set 

--insert into m_sethin 
--select hin_cd, row_no, chin_cd, set_su, del_flg, cre_id, 
--	cre_time, upd_id, upd_time
--from w_basv1050_copy
--where s_id = :s_id

[set_now_stock]
select
	coalesce(MAX(now_stock),0) as now_stock
from m_stock
where hin_cd = ':hin_cd'
;
[get_hin_atch]
select file_image, file_name
from t_hin_atch
where hin_cd = ':hin_cd'
and row_no = :row_no
;

[getImage]
select file_image from t_hin_atch
where hin_cd = ':hin_cd'
and row_no = :_row_no
;

[deleteDocRow]
delete from t_hin_atch where hin_cd = ':hin_cd' and row_no = :d_row_no;

[chk_hin_atch]
select 1 from t_hin_atch where hin_cd = ':hin_cd' and row_no = :d_row_no;