日期:2014-05-18 浏览次数:20795 次
while(@@fetch_status=0) begin set @id1 = @id update #Data_get2 set replyzsl = (select count(1) from test where id2=@id1) where id=@id1 --至少你要加入以下语句避免死循环 fetch next from cursor_table into @id end
------解决方案--------------------
应该就是少了fetch next from cursor_table into @id
语句导致你不能取到下一条记录。在第一条记录上死循环了
------解决方案--------------------
--楼主可以这样不用 游标,不会锁表,效率也很高
declare @Rows int,
@Row int,
@ID int
set @Row = 1
declare @t table(
Row int identity(1,1) not null,
Id int not null
)
insert into @t
select id from #Data_get1
set @Rows = @@ROWCOUNT
while(@Row <=@Rows)
begin
select @id = id from @t where Row = @Row
update #Data_get2 set replyzsl = (select count(1) from test where id2=@id) where id=@id
set @row = @row + 1
end