游标使用案例

DECLARE CUR_MonthID CURSOR FOR
select ID from SysUser
OPEN CUR_MonthID

declare @ID uniqueidentifier
declare @userName varchar

FETCH NEXT FROM CUR_MonthID INTO @ID /* 读取第1行数据*/

WHILE @@FETCH_STATUS = 0
BEGIN

select @userName = Name from Sales where SysUserId=@ID;
update SysUser set UserName =@userName where ID=@ID
FETCH NEXT FROM CUR_MonthID INTO @ID /* 读取下一行数据*/

END
CLOSE CUR_MonthID
deallocate CUR_MonthID

posted @ 2017-09-21 13:41  我没有领悟  阅读(123)  评论(0编辑  收藏  举报