sqlserver2000创建一个循环游标的存储过程
create proc bbb
as
declare testcursor cursor for
select count(GM_ID) as countpoint,GM_UserName from lu_sup_GuestBook_Message group by GM_UserName //声明游标
open testcursor //打开游标
declare @point int,@user_name varchar(30) //声明中间变量
fetch next from testcursor into @point,@user_name //从游标中提取第一条记录放入变量中
while(@@fetch_status = 0) //是否循环完毕
begin
update lu_sup_NETWORK_USER_INFO set user_point = user_point + @point where MyUSER_NAME = @user_name //利用变量自定义操作
fetch next from testcursor into @point,@user_name //提取下一条记录放入变量
end
close testcursor //关闭游标
deallocate testcursor //销毁游标所占资源
go
浙公网安备 33010602011771号