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.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Deleting Files After Seven Days

Author  Topic 

aturner
Starting Member

29 Posts

Posted - 2004-08-19 : 09:22:19
I currently have a table that store topics of interest that individuals can view in a seven (7) day period. The table consists of the following fields: TopicID, DateCreated, Subject, Discussion, Review, DateModified. How can I construct a stored procedure that will purge topics that are seven days old and move them to an archive table with the same data type, allowing new topics to be entered. The archive table would allow individuals to review previous topics when needed.

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2004-08-19 : 09:28:55
will this do?

insert into ArchiveTable (TopicID, DateCreated, Subject, Discussion, Review, DateModified)
select TopicID, DateCreated, Subject, Discussion, Review, DateModified
from MyTable
where DateCreated >= DateAdd(d, -7, getDate())

delete from from MyTable
where DateCreated >= DateAdd(d, -7, getDate())


Go with the flow & have fun! Else fight the flow :)
Go to Top of Page

ehorn
Master Smack Fu Yak Hacker

1632 Posts

Posted - 2004-08-19 : 09:34:38
Another design option might be to create an archive flag in the existing table. Then just update the flag.
Go to Top of Page
   

- Advertisement -