Det ser ud til, at du vil tildele en øget værdi til empno, der starter med 10.
Du kan bruge en CTE og row_number() til at gøre det. Der er ikke behov for en markør.
;with C as
(
select empno,
9 + row_number() over(order by (select 1)) as NewEmpNo
from emp
)
update C
set empno = NewEmpNo
Din markørversion kunne se sådan ud for at gøre det samme.
DECLARE @empno AS INT;
DECLARE @CurEmpNo AS INT;
SELECT @empno = 10;
DECLARE employee_cursor CURSOR FOR
SELECT empno
FROM emp
OPEN employee_cursor;
FETCH NEXT FROM employee_cursor INTO @CurEmpNo
WHILE @@FETCH_STATUS = 0
BEGIN
UPDATE emp
SET empno = @empno
WHERE CURRENT OF employee_cursor;
SELECT @empno = @empno + 1;
FETCH NEXT FROM employee_cursor INTO @CurEmpNo
END;
CLOSE employee_cursor;
DEALLOCATE employee_cursor;