游标使用案例
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