Hey Everyone,
Here is my code:
Basically there are about a 100,000 records that should expire, and not marked expired yet.
This script should loop until all records with date stamp more than 15 days old are marked as Expired. or until it hits 10000 records as marked.
The issue is that from what I can tell, it only goes though this once, and never loops back to do the next 500.
If I take the skip IF statement out, than it keeps looping to do 10000 records, even after it has finished the expired ones, and produces zero rowcounts until it has looped all the way through.
Here is my code:
Code:
...
SET @CountDeleted = 0
SET ROWCOUNT 500
delete_more1:
UPDATE tblQuarantine SET Expire = 1 WHERE ((DATEDIFF(day, MsgDate, GETDATE()) > 15) AND (Expire <> 1))
SET @CountDeleted = @CountDeleted + 500
IF @@ROWCOUNT < 1 GOTO delete_more1_skip
IF ((@@ROWCOUNT > 0) AND (@CountDeleted < 10001)) GOTO delete_more1
delete_more1_skip:
...
Basically there are about a 100,000 records that should expire, and not marked expired yet.
This script should loop until all records with date stamp more than 15 days old are marked as Expired. or until it hits 10000 records as marked.
The issue is that from what I can tell, it only goes though this once, and never loops back to do the next 500.
If I take the skip IF statement out, than it keeps looping to do 10000 records, even after it has finished the expired ones, and produces zero rowcounts until it has looped all the way through.