DECLARE @id BINARY
DECLARE @num INT
declare CUR CURSOR LOCAL
FOR
SELECT TOP (10)
[_Document156_IDRRef]
,row_number() over(PARTITION BY [_Document156_IDRRef] ORDER BY [_KeyField]) num -- ошибка cursor read only
--,[_LineNo2813] as num -- ошибки нет
FROM [testut11].[dbo].[_Document156_VT2812]
FOR UPDATE of num1
OPEN CUR
FETCH NEXT FROM CUR INTO @id, @num
WHILE @@FETCH_STATUS = 0
BEGIN
UPDATE [testut11].[dbo].[_Document156_VT2812]
SET num1 = @num
WHERE CURRENT OF CUR;
FETCH NEXT FROM CUR INTO @id, @num
END
CLOSE CUR
DEALLOCATE CUR
DECLARE @ID BINARY(32), @Key BINARY(32), @Num INT
DECLARE Renumb CURSOR FOR
SELECT [_Document156_IDRRef], [_KeyField],
ROW_NUMBER() OVER( PARTITION BY [_Document156_IDRRef] ORDER BY [_KeyField]) AS Num
FROM [_Document156_VT2812]
OPEN Renumb
FETCH NEXT FROM Renumb INTO @ID, @Key, @Num
WHILE @@FETCH_STATUS = 0
BEGIN
UPDATE _Document156_VT2812
SET _LineNo2813 = @Num
WHERE (_Document156_IDRRef = @ID) AND (_KeyField = @Key )
FETCH NEXT FROM Renumb INTO @ID, @Key, @Num
END
CLOSE Renumb
DEALLOCATE Renumb