My code looks pretty advanced.
I want to update a specific field with a unique counter, not equal to {1,2,3, ...}.
I keep getting the "Cursor ONLY EXACTLY" error.
Also: is there an easier way?
declare @MaxVal int = NULL declare @fetchVal int = NULL select @MaxVal = MAX(tp_Id)+1 from [<tableContainingInitialMaxval>] DECLARE curs01 CURSOR for select @maxVal + row_number() OVER (order by [<someUniqueField>]) from [<table2update>]; (used FOR UPDATE OF [<field2update>] but that made no difference) open curs01 FETCH NEXT FROM curs01 INTO @fetchVal; WHILE @@FETCH_STATUS = 0 begin update [<table2update>] set [<field2update>] = @fetchVal WHERE CURRENT OF curs01; FETCH NEXT FROM curs01 INTO @fetchVal; end; CLOSE curs01; DEALLOCATE curs01; GO
source share