I had to create test data that updated the date column of of 2000 records, with 10 rows of the same the date, decrementing the date by 1 on the 11th row.
Here is the T-SQL:
DECLARE @CNT INT = 0;
DECLARE @DAYSUBTRACT INT = 0;
DECLARE @ACCOUNT_ID INT;
DECLARE Update_Cursor CURSOR FOR
SELECT TOP 2000 ACCOUNT_ID
FROM ACCOUNTS;
OPEN Update_Cursor;
FETCH NEXT FROM Update_Cursor INTO @ACCOUNT_ID;
WHILE @@FETCH_STATUS = 0
BEGIN
UPDATE ACCOUNTS
SET DATE_OPENED = DATEADD(day,@DAYSUBTRACT,SYSDATETIME())
WHERE ACCOUNT_ID = @ACCOUNT_ID
SET @CNT = @CNT + 1;
IF (@CNT%10 = 0) SET @DAYSUBTRACT = @DAYSUBTRACT - 1;
FETCH NEXT FROM Update_Cursor INTO @ACCOUNT_ID;
END;
CLOSE Update_Cursor;
DEALLOCATE Update_Cursor;
GO
Is there away to accomplish this without using a cursor in T-SQL?
TOPwithoutORDER BY, so your results are indeterminate.