create procedure testc
AsDECLARE authors_cursor CURSOR FOR
SELECT * FROM testcur oRDER BY idOPEN authors_cursor-- Perform the first fetch.
FETCH NEXT FROM authors_cursordeclare @i int
set @i=1
WHILE @@FETCH_STATUS = 0
BEGIN
   update testcur set testid=@i where id=@i
set @i=@i+1
   FETCH NEXT FROM authors_cursor
ENDCLOSE authors_cursor
DEALLOCATE authors_cursor
GO

解决方案 »

  1.   

    create procedure testcAsDECLARE authors_cursor CURSOR FOR
    SELECT * FROM testcur oRDER BY idOPEN authors_cursor-- Perform the first fetch.
    FETCH NEXT FROM authors_cursordeclare @i int
    set @i=1
    WHILE @@FETCH_STATUS = 0
    BEGIN
       update testcur set testid=@i
    set @i=@i+1
       FETCH NEXT FROM authors_cursor
    ENDCLOSE authors_cursor
    DEALLOCATE authors_cursor
    GO
      

  2.   

    update authors_cursor set testid=@i 出错了, 不能看这样用的,好像标准的sql可以利用游标需该记录,我忘了,改天给你找找 
      

  3.   

    UPDATE testcur testid=@i  WHERE CURRENT OF authors_cursor