游标操作实例
更新歌手MV歌曲数和歌手总人气
declare @gsid int
declare @songnum int
declare @songallhit int
declare rq cursor for select distinct gsid from MV歌曲表 where sh=1 and isok=0 order by gsid asc
open rq
fetch next from rq into @gsid while @@FETCH_STATUS = 0
begin
select @songnum =count(id),@songallhit=sum(allhit) from MV歌曲表 where and sh=1 and isok=0
update 歌手表 set where gsid= @gsid
fetch next from rq into @gsid
end
close rq
deallocate rq