Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
mr_dayal
Starting Member
37 Posts |
Posted - 2008-07-25 : 07:36:04
|
| I have a table with following dataItem Id DatePower Kiting(Foll Kite) 24/07/2008 7:21:21 PMIKO Kiteboarder Level III 24/07/2008 7:40:22 PMPower Kiting(Foll Kite) 25/07/2008 3:55:04 PMIKO Kiteboarder Level I 25/07/2008 3:57:23 PMIKO Kiteboarder Level I 24/07/2008 7:31:08 PMIKO Kiteboarder Level II 24/07/2008 7:34:49 PMNow this database is made in sql express edition and is used for a web site..I want to delete those records whose date filed is less then one day ago...(records which r older then 24 hours).. Mr Dayal |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-07-25 : 07:40:39
|
| You can create a sql agent job which fires the delete statement to delete records older than 24 hrs. then schedule the job to be run as per your convenient schedule.the delete statement will be likeDELETE FROM YourTable WHERE DateField < DATEADD(d,DATEDIFF(d,0,GETDATE()),-1) |
 |
|
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2008-07-25 : 11:53:56
|
quote: Originally posted by visakh16 DELETE FROM YourTable WHERE DateField < DATEADD(d,DATEDIFF(d,0,GETDATE()),-1)
Just to be clear, that will delte all records from the previous day. If you want a rolling 24 hour window then you probably should just subtract 24 hours from the current datetime: [CODE]DELETE FROM YourTable WHERE DateField < DATEADD(HOUR, -24, GETDATE())[/CODE] |
 |
|
|
|
|
|