Home All Groups Group Topic Archive Search About

Can't be rocket science to delete data older than 30 days?

Author
29 Jun 2006 7:37 PM
Kevini
Can it ?

is it this simple? Or is it supposed to > ?
DELETE FROM LOGRECS
WHERE datediff(d,getdate(), time)<=30

Author
29 Jun 2006 7:42 PM
Anith Sen
Try:

DELETE FROM tbl
WHERE time_col <= DATEADD( d, -30, CURRENT_TIMESTAMP ) ;

--
Anith
Author
29 Jun 2006 7:54 PM
Stu
Anith Sen wrote:
> Try:
>
> DELETE FROM tbl
>  WHERE time_col <= DATEADD( d, -30, CURRENT_TIMESTAMP ) ;
>
> --
> Anith

When in doubt, don't delete.

SELECT MAX(time_col)
-- DELETE
FROM tbl
WHERE time_col <= DATEADD( d, -30, CURRENT_TIMESTAMP ) ;

Measure twice, cut once.
Author
29 Jun 2006 9:21 PM
Anith Sen
>> Measure twice, cut once.

Couldn't agree more !

--
Anith
Author
29 Jun 2006 7:43 PM
Aaron Bertrand [SQL Server MVP]
You're saying within the last 30 days.  This statement might be more logical
to follow:

DELETE LogRecs
    WHERE [time] < GETDATE() - 30;

or

DELETE LogRecs
    WHERE [time] < DATEADD(DAY, -30, GETDATE());





Show quote
"Kevini" <Kev***@discussions.microsoft.com> wrote in message
news:5882D56F-7395-46A4-A49E-D0B096A47D8F@microsoft.com...
> Can it ?
>
> is it this simple? Or is it supposed to > ?
> DELETE FROM LOGRECS
> WHERE datediff(d,getdate(), time)<=30
Author
29 Jun 2006 7:57 PM
Kevini
I only want the last 30 days so nothing earlier than May 29 or should I say
records form today and back 30 days

Show quote
"Aaron Bertrand [SQL Server MVP]" wrote:

> You're saying within the last 30 days.  This statement might be more logical
> to follow:
>
> DELETE LogRecs
>     WHERE [time] < GETDATE() - 30;
>
> or
>
> DELETE LogRecs
>     WHERE [time] < DATEADD(DAY, -30, GETDATE());
>
>
>
>
>
> "Kevini" <Kev***@discussions.microsoft.com> wrote in message
> news:5882D56F-7395-46A4-A49E-D0B096A47D8F@microsoft.com...
> > Can it ?
> >
> > is it this simple? Or is it supposed to > ?
> > DELETE FROM LOGRECS
> > WHERE datediff(d,getdate(), time)<=30
>
>
>
Author
29 Jun 2006 8:24 PM
Aaron Bertrand [SQL Server MVP]
>I only want the last 30 days

But your subject says "data older than 30 days"

If you want rows that are within the last 30 days, then

WHERE [time] > DATEADD(DAY, -30, GETDATE())
AND [time] <= GETDATE()
Author
30 Jun 2006 5:26 AM
Arnie Rowland
Ouch! I hate seeing a column containing a date named [Time]...How utterly
and needlessly confusing.

--
Arnie Rowland, YACE*
"To be successful, your heart must accompany your knowledge."

*Yet Another Certification Exam


Show quote
"Aaron Bertrand [SQL Server MVP]" <ten.xoc@dnartreb.noraa> wrote in message
news:u6h3KR7mGHA.4620@TK2MSFTNGP05.phx.gbl...
> You're saying within the last 30 days.  This statement might be more
> logical to follow:
>
> DELETE LogRecs
>    WHERE [time] < GETDATE() - 30;
>
> or
>
> DELETE LogRecs
>    WHERE [time] < DATEADD(DAY, -30, GETDATE());
>
>
>
>
>
> "Kevini" <Kev***@discussions.microsoft.com> wrote in message
> news:5882D56F-7395-46A4-A49E-D0B096A47D8F@microsoft.com...
>> Can it ?
>>
>> is it this simple? Or is it supposed to > ?
>> DELETE FROM LOGRECS
>> WHERE datediff(d,getdate(), time)<=30
>
>
Author
30 Jun 2006 6:39 AM
Aaron Bertrand [SQL Server MVP]
> Ouch! I hate seeing a column containing a date named [Time]...How utterly
> and needlessly confusing.

Hey, I didn't name that column, don't shoot the messenger!  :-)
Author
30 Jun 2006 6:57 AM
Mike Hodgson
Quick, hide - I can hear Celko coming...

--
*mike hodgson*
http://sqlnerd.blogspot.com



Aaron Bertrand [SQL Server MVP] wrote:

Show quote
>>Ouch! I hate seeing a column containing a date named [Time]...How utterly
>>and needlessly confusing.
>>   
>>
>
>Hey, I didn't name that column, don't shoot the messenger!  :-)
>
>

>
Author
29 Jun 2006 7:56 PM
Tracy McKibben
Kevini wrote:
> Can it ?
>
> is it this simple? Or is it supposed to > ?
> DELETE FROM LOGRECS
> WHERE datediff(d,getdate(), time)<=30

It helps to have the rocket pointed in the right direction...  :-)

WHERE DATEDIFF(d, time, GETDATE()) > 30
Author
29 Jun 2006 8:05 PM
Kevini
Thanks Guys...Aaron's worked beautifully. And the rocket pointed the right
way:-)

Show quote
"Tracy McKibben" wrote:

> Kevini wrote:
> > Can it ?
> >
> > is it this simple? Or is it supposed to > ?
> > DELETE FROM LOGRECS
> > WHERE datediff(d,getdate(), time)<=30
>
> It helps to have the rocket pointed in the right direction...  :-)
>
> WHERE DATEDIFF(d, time, GETDATE()) > 30
>
Author
29 Jun 2006 8:18 PM
Tracy McKibben
Kevini wrote:
> Thanks Guys...Aaron's worked beautifully. And the rocket pointed the right
> way:-)
>

Houston, we have lift-off!
Author
29 Jun 2006 8:28 PM
impslayer
Kevini wrote:
> Thanks Guys...Aaron's worked beautifully. And the rocket pointed the right
> way:-)
>

So, is it really a rocket, or are you just happy to see us ;)

    /impslayer, aka Birger Johansson

AddThis Social Bookmark Button