Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Help Groups for Snitz Forums 2000 Users
 Help: Database: MS SQL Server
 T-SQL to delete archive
 New Topic  Topic Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

DavidRhodes
Senior Member

United Kingdom
1222 Posts

Posted - 15 October 2004 :  09:29:27  Show Profile
Does anyone have any T-SQL handy to delete archives older than a certain date?

The UK MkIVs Forum

D3mon
Senior Member

United Kingdom
1685 Posts

Posted - 15 October 2004 :  09:44:15  Show Profile  Visit D3mon's Homepage
DELETE tbl[mytable]
WHERE datefield <= '1 jan 2004'
AND archived


Snitz 'Speedball' : Site Integration Mod : Friendly Registration Mod
"In war, the victorious strategist only seeks battle after the victory has been won"
Go to Top of Page

DavidRhodes
Senior Member

United Kingdom
1222 Posts

Posted - 15 October 2004 :  09:48:01  Show Profile
I mean from Snitz, the FORUM_A_REPLY and FORUM_A_TOPICS tables. Date format is YYYYMMDDHHMMSS.

The UK MkIVs Forum
Go to Top of Page

D3mon
Senior Member

United Kingdom
1685 Posts

Posted - 15 October 2004 :  09:55:28  Show Profile  Visit D3mon's Homepage
Ah, I've never actually looked at the Archive table, but it will be along these lines:

DELETE FORUM_A_TOPICS
WHERE datefield <= '1 jan 2004'

MSSQL should be able to accept the date like that.


Snitz 'Speedball' : Site Integration Mod : Friendly Registration Mod
"In war, the victorious strategist only seeks battle after the victory has been won"
Go to Top of Page

DavidRhodes
Senior Member

United Kingdom
1222 Posts

Posted - 15 October 2004 :  10:05:33  Show Profile
I've got this so far

SELECT * FROM FORUM_A_TOPICS t
INNER JOIN FORUM_A_REPLY r
ON r.TOPIC_ID = t.TOPIC_ID
WHERE r.R_DATE < '20031015000000'


Obviously that is a select not a delete, does this look correct. It should delete all archived topics and replies old than 1 year when I replace "SELECT * FROM" with "DELETE"

The UK MkIVs Forum
Go to Top of Page

CPO
Starting Member

5 Posts

Posted - 18 October 2004 :  20:31:26  Show Profile
Hi David!

Your script will almost delete from the FORUM_A_TOPICS table. The reason I say almost, is that you would get a syntax error with the aliasing of the table coming right after the table name in the
DELETE FORUM_A_TOPICS t
part of it.
Also, you can only delete from one table at a time so it will not delete from the FORUM_A_REPLY table.

I modified your script a little for the delete. You might use the getdate() - 365 (second script) so that you don't have to change the date every time you run it, just a thought... Hope this helps!!!


DELETE T
FROM FORUM_A_TOPICS T
INNER JOIN FORUM_A_REPLY R
ON R.TOPIC_ID = T.TOPIC_ID
WHERE R.R_DATE < '20031015000000'

DELETE T
FROM FORUM_A_TOPICS T
INNER JOIN FORUM_A_REPLY R
ON R.TOPIC_ID = T.TOPIC_ID
WHERE R.R_DATE < getdate() - 365
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Topic Locked
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.35 seconds. Powered By: Snitz Forums 2000 Version 3.4.07