Wednesday, March 21, 2012

Purge old ROWS

looking for a script that will purge rows that are 2
months old. I would like to run this as a Scheduled job..
On Tue, 1 Jun 2004 11:05:01 -0700, Rick wrote:

>looking for a script that will purge rows that are 2
>months old. I would like to run this as a Scheduled job..
Hi Rick,
Assuming your table is called MyTable and the creation date of each row is
stored in a column named CrDate, use this:
DELETE FROM MyTable
WHERE CrDate < dateadd(month, -2, getdate())
Untested - test it first, in a transaction. Rollback or commit as needed.
Don't put it in a scheduled job until you've tested it thoroughly.
Best, Hugo
(Remove _NO_ and _SPAM_ to get my e-mail address)
|||Thanks for the information, It worked perfectly. FYI: I am using this
for ODBC logging on IIS web servers. They send the logs to a SQL server
and I purge them as they get old.
Works very well thanks,
DELETE FROM inetlog
WHERE LogTime < dateadd(month, -2, getdate())
*** Sent via Developersdex http://www.codecomments.com ***
Don't just participate in USENET...get rewarded for it!

No comments:

Post a Comment