Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Needing a certain query

Status
Not open for further replies.

Jimuniguy

Technical User
Mar 6, 2002
363
GB
Hello,

I have a table called "forum" in a database with 6 fields:

Forumname
Username
Topic
Topicdata
Date
Delete

And basically i want to copy all the data from all fields where the date say is older then 30 days and copy it into a new table called "archive" with the following fields:

ArchiveForumname
ArchiveUsername
ArchiveTopic
ArchiveTopicdata
ArchiveDate
ArchiveDelete

And then delete from the original table the posts.

Problem is i don't seem to be able to get it to work, can someone please help me?

Thanks :)

Jimuniguy
And then delete it from the original table

 
Try:

Code:
INSERT INTO archive (
   ArchiveForumname, 
   ArchiveUsername, 
   ArchiveTopic, 
   ArchiveTopicdata, 
   ArchiveDate, 
   ArchiveDelete)
SELECT 
   Forumname, 
   Username, 
   Topic, 
   Topicdata, 
   Date, 
   Delete
FROM forum
WHERE Date < AddDate(CurDate(), -30);

DELETE FROM forum
WHERE Date < AddDate(CurDate(), -30);
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top