| 发表于:2007-05-10 09:28:502楼 得分:0 |
alter procedure sp_set_settb_cmpstn_cd @dbuser char(10) ,@returnvalue int output as begin set @tmp_tgpc = ' ' declare wkrcd cursor for select wk.hin, wk.uchi, wk.tgpc, wk.cgpc, wk.fgpc, wk.pgpc, cdm.set_rprsnttv_cd from set_cmpstn_wk wk left join set_cmpstn_mst m on wk.hin=m.hin and wk.uchi=m.uchi and wk.tgpc=m.tgpc and wk.cgpc=m.cgpc and wk.fgpc=m.fgpc and wk.pgpc=m.pgpc and m.del_kbn= '1 ' left join set_rprsnttv_cd_mst cdm on wk.tgpc = cdm.tgpc and cdm.del_kbn= '0 ' where m.hin is null and m.uchi is null and m.tgpc is null and m.cgpc is null and m.fgpc is null and m.pgpc is null and cdm.set_rprsnttv_cd is not null and wk.prcss_kbn= '1 ' order by wk.tgpc open wkrcd fetch next from wkrcd into @hin, @uchi, @tgpc, @cgpc, @fgpc, @pgpc, @kyuketa while @@fetch_status = 0 begin if @tmp_tgpc != @tgpc begin set @tmp_tgpc = @tgpc select @cmpstncdchg = max(set_cmpstn_cd) from set_cmpstn_wk where set_cmpstn_cd like @kyuketa+ '% ' and del_kbn= '0 ' group by set_cmpstn_cd if @cmpstncdchg is null or ltrim(@cmpstncdchg) = ' ' begin set @counter = '000 ' end else begin --12桁コードを計算する set @counter = right(rtrim(@cmpstncdchg),3) end end set @counter = right( '000 '+convert(varchar(3),@counter+1),3) if @counter = '999 ' begin set @returnvalue = 5 return 5 end update set_cmpstn_wk set set_cmpstn_cd=@kyuketa+@counter, updt_dt=getdate(), updt_usr_id=@dbuser where prcss_kbn= '1 ' and hin = @hin and uchi = @uchi and tgpc = @tgpc and cgpc = @cgpc and fgpc = @fgpc and pgpc = @pgpc and del_kbn= '0 ' and ltrim(set_cmpstn_cd) = ' ' --[ カーソル情報 取得 ] fetch next from wkrcd into @hin, @uchi, @tgpc, @cgpc, @fgpc, @pgpc, @kyuketa end close wkrcd deallocate wkrcd set @returnvalue = 0 end | | |
|