SQL(游标的使用)

 declare cur_staff cursor
  for select id from #tmp_staff
 open cur_staff
 fetch next from cur_staff into @staff_id

 while @@FETCH_STATUS=0
 begin
  set @sql='
   update #tmp_service
   set trackstaff = '+convert(varchar,@staff_id)+'
   where id in
   (select top '+convert(varchar,@AssNumPerStaff)+' id
   from  #tmp_service where trackstaff is null order by id)'
  --print @sql
  exec (@sql)
  fetch next from cur_staff into @staff_id
 end
 
 close cur_staff
 deallocate cur_staff

posted on 2007-11-14 09:58  ferrari  阅读(169)  评论(0编辑  收藏  举报

导航