简单的存储过程实现更新

 

代码
CREATE procedure MyUpdate AS

declare @ItemNo varchar(10), @bh varchar(10) --定义变量

select identity(int, 1,1) dd, bh into #s from sys_HY

declare Sbj cursor for select right('0000'+ rtrim(dd),3), bh from #s --定义一个游标查询临时表

open Sbj --打开游标
fetch next from Sbj into @ItemNo, @bh --把游标指向的当前结果放入变量中
while ( @@Fetch_status = 0)
begin
-- select @ItemNo item, @bh
update sys_hy set bh = @ItemNo where bh = @bh
fetch next from Sbj into @ItemNo, @bh
end
close Sbj --关闭游标
deallocate Sbj --删除游标引用
drop table #s


exec myupdate --执行存储过程

drop procedure myupdate

 

posted @ 2010-01-26 00:15  一 点  阅读(144)  评论(0编辑  收藏  举报