Click here to Skip to main content
14,640,711 members
Rate this:
Please Sign up or sign in to vote.
See more:
I am developing an application in which i have table with 3 columns (id, name and date).

Now in date field I am storing date the user joined, but now i want to delete the user records which are over 4 days old, from the original date of joining.


I want something like this...
there is entry on date field 4/6/2013
Now after 4 days i.e. on 8/6/2013 all the records having 4/6/2013 date will be removed autometically... This should be done automatically.. Lets say when the server time gets 12:00AM it should be happen automatically... How can i achieve this?
Please help me out..?

Thanks in advance.
Posted
Updated 5-Apr-13 16:02pm
v4
Comments
[no name] 5-Apr-13 15:32pm
   
You need an SQL Job Agent, scheduled task or a service.
jkirkerx 5-Apr-13 18:02pm
   
I improved your question, but after that, the question was still sort of unclear to me.

You want to delete the records after 4 days, or erase the date time value after 4 days?

You can do that when a user joins, when you add the record, run a sql statement that does cleanup after the insert record.
Naikniket 5-Apr-13 22:00pm
   
I want something like this...
there is entry on date field 4/6/2013
Now after 4 days i.e. on 8/6/2013 all the records having 4/6/2013 date will be removed autometically... This should be done automatically.. Lets say when the server time gets 12:00AM it should be happen automatically...

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

delete from dbo.Table where Date_Column<GETDATE()-4


try it.it should work..

-Anurag
   
v2
Comments
Naikniket 5-Apr-13 22:01pm
   
I want something like this...
there is entry on date field 4/6/2013
Now after 4 days i.e. on 8/6/2013 all the records having 4/6/2013 date will be removed autometically... This should be done automatically.. Lets say when the server time gets 12:00AM it should be happen automatically...
Anurag Sinha V 6-Apr-13 7:58am
   
Ok...I see...you can put the above delete statement in a job and schedule the job to run daily at whatever time you want...You can find jobs in SQL server agent..right click it and you can see some default jobs..create a new one and try

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100