[updateOriginal]
select func_load_basr0311(:s_id);

[selectRecords]
select 
	s_id,
	kbn,
	den_no,
	s_row_no,
	row_order,
	'No.'||mitsumori_no as mitsumori_no,
	mitsu_kigen_ymd,
	mitsu_kigen_mongon,
	noki,
	keisyou,
	keisyou_2,
	row_no,
	coalesce(row_page,0) as row_page,
	input_ymd,
	syori_ymd,
	zeinuki_gaku,
	zei_gaku,
	tok_tan,
	zeikomi_gaku,
	u_biko1,
	u_biko2,
	u_biko3,
	u_biko4,
	u_biko5,
	u_biko6,
	unit_nm,
	hin_cd,
	hin_nm,
	tok_hacyu_no,
	suryo,
	tanka,
	kingaku,
	jucyu_su,
	tani,
	title1,
	title2,
	payment_term,
	nonyu_ymd,
	tok_cd,
	tok_nm,
	yubin_no,
	jucyu_row_no,
	tori_cond,
	biko1,
	biko2,
	biko3,
	biko4,
	hosoku1,
	hosoku2,
	nonyu_nm,
	nonyu_yubin_no,
	nonyu_tan,
	keisyou2,
	keisyou2_2,
	brkey,
	((brkey)+1) as page_no,
	((select
		max(w.brkey) as max_page
	from w_basr0310 w
	where 1=1
	and w.s_id = '&7')+1) as max_page_no,
	disp_row_no,
	total_kingaku
from w_basr0310 w
where 1=1
and w.s_id = '&7'
order by den_no,s_row_no,kbn,row_order;


[selectRecords2]
select
	   w.s_id
	 , w.den_no
	 , w.row_no
	 , w.s_row_no
	 , w.mitsumori_no
	 , 'No.'||w.mitsumori_no as mitsumori_no_s
	 , w.page_no
	 , w.hin_nm
	 , w.input_ymd
	 , w.zeinuki_gaku
	 , w.zei_gaku
	 , w.tok_tan
	 , w.zeikomi_gaku
	 , w.biko1
	 , w.nonyu_nm
	 , w.cat_cd_nm
	 , w.hin_tani_nm
	 , w.ban_tani_nm
	 , w.hin_cd
	 , w.ban_nm
 	 , w.row_no||'. '||w.ban_nm as ban_nm_s
	 , w.hin_su
	 , w.hin_tani
	 , w.jucyu_su
	 , w.jucyu_su||' '||w.ban_tani_nm as jucyu_su_s
	 , w.ban_su
	 , w.tok_hacyu_no
	 , w.suryo
	 ,(case (jucyu_gokei_su)
		 when '1' then null
		 else tanka
	   end) as dis_tanka
	 ,(case (w.tanka)
		when 0 then null
		else (case (w.hin_su)
			when '1' then null
			else w.tanka
			end)
		end) as tanka
	 , w.kingaku
	 , w.row_page
	 ,(select
		max(w.row_page)
		from w_basr0320 w
		inner join w_report ww on (w.den_no = ww.den_no and ww.s_id = w.s_id and (w.row_no-1) = ww.row_no)
		where 1=1
		and w.s_id = '&7') as max_page_no
	 , w.hosoku1
	 , (case (w.hosoku2)
		when '0' then ' '
		else w.hosoku2
		end) as hosoku2
	 , (case (w.meisai_biko)
		when '0' then ' '
		else w.meisai_biko
		end) as meisai_biko
	 , w.title1
	 , w.nonyu_ymd
	 , w.tok_cd
	 , w.tok_nm
	 , w.jucyu_row_no
	 , w.yubin_no
	 , w.nonyu_yubin_no
	 , w.nonyu_tan
	 , w.jucyu_gokei_su
	 , w.mitsu_kingaku
	 , w.sir_kingaku
from w_basr0320 w
--inner join w_report ww on (w.den_no = ww.den_no and ww.s_id = w.s_id and (w.row_no-1) = ww.row_no)
where 1=1
and w.s_id = '&7'
order by den_no,row_no,s_row_no;

