I have a table in my DB that I would like to restrict to recent records
only. Recent being the last 4 months. Can someone help me determine the
easiest and most maintenance free way to accomplish this?
Thank You"Shawn" <skfabc@.yahoo.com> wrote in message
news:ezb1obNHEHA.3556@.TK2MSFTNGP10.phx.gbl...
> I have a table in my DB that I would like to restrict to recent records
> only. Recent being the last 4 months. Can someone help me determine the
> easiest and most maintenance free way to accomplish this?
> Thank You
Presumably you have a column with creation date included in the table
schema. In which case create a SQL Server Agent TSQL job that contains the
SQL:
DELETE *
FROM tablename
WHERE dateCol < GETDATE() - 120.
Schedule it to run regularly (e.g. every night). You might even want to add
it to the backup job.
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.647 / Virus Database: 414 - Release Date: 29/03/2004|||I agree with Bobs solution, but here is some SQL that will
find values greater than 4 months rather than 120 days
(although I am being very picky)
delete
FROM order
WHERE DATEDIFF(month, orderdate, getdate()) > 4
J
>--Original Message--
>I have a table in my DB that I would like to restrict to
recent records
>only. Recent being the last 4 months. Can someone help me
determine the
>easiest and most maintenance free way to accomplish this?
>Thank You
>
>.
>|||"Julie" <anonymous@.discussions.microsoft.com> wrote in message
news:1a22a01c41d4d$1f22acf0$a101280a@.phx.gbl...
> I agree with Bobs solution, but here is some SQL that will
> find values greater than 4 months rather than 120 days
> (although I am being very picky)
> delete
> FROM order
> WHERE DATEDIFF(month, orderdate, getdate()) > 4
LOL I was going to post that, but had a sudden doubt as to whether DATEDIFF
was TSQL or VB, couldn't check, so I chickened out.
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.655 / Virus Database: 420 - Release Date: 08/04/2004
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment