使用游标批量初始化密码

create  proc [dbo].[up_tuser_updatepwd]

AS

declare @indextable table(rowid int identity(1,1),nid int)

insert into @indextable(nid) select userID from tuser

declare @uid int

declare laon_cursor cursor for 

select  nid from @indextable

open laon_cursor 

fetch next from laon_cursor 

into @ExpertID

 while @@fetch_status = 0  --FETCH 语句成功。

 begin 

declare @randid

int set @randid = 0 while len(@randid)<>6   

 begin       

set @randid =convert(int, substring(convert( CHAR(20),rand()),3, 6)) -- 六位数密码

end

update tuser set upwd =@randid where userID=@uid

FETCH NEXT from laon_cursor 

into @uid

end 

close laon_cursor 

deallocate laon_cursor

go

posted @ 2011-07-20 08:45  Cynosure鱼  阅读(164)  评论(0编辑  收藏  举报