初学者又来提问:
set @a=1
DECLARE Num_Cursor CURSOR FOR
select number from mobile where state=0 and upline=@upline order by number
OPEN Num_Cursor
FETCH NEXT FROM Num_Cursor
WHILE (@@FETCH_STATUS = 0)
BEGIN
FETCH NEXT FROM Num_Cursor
set @a=@a+1
END
CLOSE Num_Cursor
DEALLOCATE Num_Cursor
select @a
两个问题,1个是在循环中怎么对number字段进行操作,也就是怎么取出来它的值?
第二个问题是如果取不到相对应的记录为什么最后select @a的值会是2,谢谢回答我问题的朋友了!
------解决方案----------------------1
declare @number int
set @a=1
DECLARE Num_Cursor CURSOR FOR
select number from mobile where state=0 and upline=@upline order by number
OPEN Num_Cursor
FETCH NEXT FROM Num_Cursor into @number
WHILE (@@FETCH_STATUS = 0)
BEGIN
FETCH NEXT FROM Num_Cursor into @number
set @a=@a+1
END
CLOSE Num_Cursor
DEALLOCATE Num_Cursor
select @a