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
 Faster MS SQL Archive Script (BETA!)
 New Topic  Topic Locked
 Printer Friendly
Previous Page
Author Previous Topic Topic Next Topic
Page: of 3

ruirib
Snitz Forums Admin

Portugal
26364 Posts

Posted - 26 September 2003 :  07:39:46  Show Profile  Send ruirib a Yahoo! Message
Al, I haven't been able to have a look at this yet. Been quite busy, will have a look when I can. Sorry .


Snitz 3.4 Readme | Like the support? Support Snitz too
Go to Top of Page

Jeepaholic
Average Member

USA
697 Posts

Posted - 28 September 2003 :  14:57:29  Show Profile  Visit Jeepaholic's Homepage
Not a massive problem at this point, Rui. I just need to get things archived in the next couple weeks. Thanks for any insight you might be able to provide!

EDIT: Changed the title of this topic to be more specific

Al Bsharah
Aholics.com

Jeepaholics Anonymous
Broncoholics Anonymous
Network Insight
Go to Top of Page

Jeepaholic
Average Member

USA
697 Posts

Posted - 19 November 2003 :  13:21:16  Show Profile  Visit Jeepaholic's Homepage
OK...here it is with the forum count updating scripts included. Someone please take a look at this and let me know if I'm missing something, or mis-calculating... USE AT YOUR OWN RISK and BACKUP YOUR FORUM DATABASE FIRST!

Question: What is U_COUNT in the FORUM_TOTALS table used for?

=========================

DECLARE
	@ArchiveDate nvarchar(14),
	@ArchiveForumID int

SET
	@ArchiveDate = '20030701000000'  -- Date to archive from (YYYYMMDDHHMMSS)
SET
	@ArchiveForumID = 35  -- Forum ID to Archive


-- Create temp table that will hold TOPIC_ID's to archive
CREATE TABLE #TOPIC_IDs
(
	TOPIC_ID int
)

-- Fill temp table with TOPIC_ID's to archive
INSERT INTO
	#TOPIC_IDs
-- Query finds topics started (and edited) before archive date
SELECT
	TOPIC_ID
FROM
	FORUM_TOPICS AS FT
WHERE
	T_DATE < @ArchiveDate
AND
	-- If no last edit date (NULL), return lowest date possible
	ISNULL(T_LAST_EDIT,'00000000000000') < @ArchiveDate
	
AND
	FORUM_ID = @ArchiveForumID
AND
	-- Subquery to determine if any replies (or edits) are 
	--  AFTER the archive date.  If so, do not archive topic.
	(SELECT
		COUNT(*)
	FROM
		FORUM_REPLY AS FR
	WHERE
		(R_DATE >= @ArchiveDate
		OR
		-- If no last edit date (NULL), return lowest date possible
		ISNULL(R_LAST_EDIT,'00000000000000') >= @ArchiveDate)
	AND
		FR.TOPIC_ID = FT.TOPIC_ID
	) = 0


-- Copy TOPIC's to archive table
INSERT INTO
	FORUM_A_TOPICS
	(CAT_ID,
	FORUM_ID,
	TOPIC_ID,
	T_STATUS,
	T_MAIL,
	T_SUBJECT,
	T_MESSAGE,
	T_AUTHOR,
	T_REPLIES,
	T_UREPLIES,
	T_VIEW_COUNT,
	T_LAST_POST,
	T_DATE,
	T_LAST_POSTER,
	T_IP,
	T_LAST_POST_AUTHOR,
	T_LAST_POST_REPLY_ID,
	T_ARCHIVE_FLAG,
	T_LAST_EDIT,
	T_LAST_EDITBY,
	T_STICKY,
	T_SIG,
	T_EVENT_DATE,
	T_ISEVENT)
SELECT
	CAT_ID,
	FORUM_ID,
	TOPIC_ID,
	T_STATUS,
	T_MAIL,
	T_SUBJECT,
	T_MESSAGE,
	T_AUTHOR,
	T_REPLIES,
	T_UREPLIES,
	T_VIEW_COUNT,
	T_LAST_POST,
	T_DATE,
	T_LAST_POSTER,
	T_IP,
	T_LAST_POST_AUTHOR,
	T_LAST_POST_REPLY_ID,
	T_ARCHIVE_FLAG,
	T_LAST_EDIT,
	T_LAST_EDITBY,
	T_STICKY,
	T_SIG,
	T_EVENT_DATE,
	T_ISEVENT
FROM
	FORUM_TOPICS
WHERE
	TOPIC_ID
	IN
	(SELECT
		TOPIC_ID
	FROM
		#TOPIC_IDs)


-- Copy REPLY's to archive table
INSERT INTO
	FORUM_A_REPLY
	(CAT_ID,
	FORUM_ID,
	TOPIC_ID,
	REPLY_ID,
	R_MAIL,
	R_AUTHOR,
	R_MESSAGE,
	R_DATE,
	R_IP,
	R_STATUS,
	R_LAST_EDIT,
	R_LAST_EDITBY,
	R_SIG)
SELECT
	CAT_ID,
	FORUM_ID,
	TOPIC_ID,
	REPLY_ID,
	R_MAIL,
	R_AUTHOR,
	R_MESSAGE,
	R_DATE,
	R_IP,
	R_STATUS,
	R_LAST_EDIT,
	R_LAST_EDITBY,
	R_SIG
FROM
	FORUM_REPLY
WHERE
	TOPIC_ID
	IN
	(SELECT
		TOPIC_ID
	FROM
		#TOPIC_IDs)

-- Delete TOPIC's from main table
DELETE
FROM
	FORUM_TOPICS
WHERE
	TOPIC_ID
	IN
	(SELECT
		TOPIC_ID
	FROM
		#TOPIC_IDs)

-- Delete REPLY's from main table
DELETE
FROM
	FORUM_REPLY
WHERE
	TOPIC_ID
	IN
	(SELECT
		TOPIC_ID
	FROM
		#TOPIC_IDs)

DROP TABLE #TOPIC_IDs

-- Update FORUM_TOTALS Counts
UPDATE
	FORUM_TOTALS
SET
	P_COUNT = (
		SELECT
			COUNT(*)
		FROM
			FORUM_REPLY
		),
	P_A_COUNT = (
		SELECT
			COUNT(*)
		FROM
			FORUM_A_REPLY
		),
	T_COUNT = (
		SELECT
			COUNT(*)
		FROM
			FORUM_TOPICS
		),
	T_A_COUNT = (
		SELECT
			COUNT(*)
		FROM
			FORUM_A_TOPICS
		)

-- Update Specific Forum Counts
UPDATE
	FORUM_FORUM
SET
	F_TOPICS = (
		SELECT
			COUNT(*)
		FROM
			FORUM_TOPICS
		WHERE
			FORUM_ID = @ArchiveForumID
		),
	F_COUNT = (
		SELECT
			COUNT(*)
		FROM
			FORUM_REPLY
		WHERE
			FORUM_ID = @ArchiveForumID
		),
	F_A_TOPICS = (
		SELECT
			COUNT(*)
		FROM
			FORUM_A_TOPICS
		WHERE
			FORUM_ID = @ArchiveForumID
		),
	F_A_COUNT = (
		SELECT
			COUNT(*)
		FROM
			FORUM_A_REPLY
		WHERE
			FORUM_ID = @ArchiveForumID
		)
WHERE
	FORUM_ID = @ArchiveForumID
								

GO

Al Bsharah
Aholics.com

Jeepaholics Anonymous
Broncoholics Anonymous
Network Insight

Edited by - Jeepaholic on 19 November 2003 13:24:53
Go to Top of Page

ruirib
Snitz Forums Admin

Portugal
26364 Posts

Posted - 19 November 2003 :  20:25:17  Show Profile  Send ruirib a Yahoo! Message
I think U_COUNT is the number of registered users. Well done Al .


Snitz 3.4 Readme | Like the support? Support Snitz too
Go to Top of Page

Jeepaholic
Average Member

USA
697 Posts

Posted - 20 November 2003 :  01:48:15  Show Profile  Visit Jeepaholic's Homepage
I ran it on a test forum countless times and finally ran it on the live one. I think it pretty close, if not right on. I'll update the first post with the code.

Duh (on U_COUNT). <laugh> Didn't think of that for some reason.

Al Bsharah
Aholics.com

Jeepaholics Anonymous
Broncoholics Anonymous
Network Insight
Go to Top of Page

jeepgen
New Member

Italy
73 Posts

Posted - 30 November 2003 :  08:50:48  Show Profile  Visit jeepgen's Homepage  Send jeepgen a Yahoo! Message
please, help my sql forum.
When i try to archive, i get an error.
It's like : "no multiple (something) may be done"
Will this mod solve the problem??
And: where have i to run it?
Thanks in advance.
PS Jeepaholics, i am one of your members, u have one of the best jeep-page in the world

www.jeeptelevision.com

Go to Top of Page

ruirib
Snitz Forums Admin

Portugal
26364 Posts

Posted - 30 November 2003 :  09:46:27  Show Profile  Send ruirib a Yahoo! Message
quote:
Originally posted by jeepgen

please, help my sql forum.
When i try to archive, i get an error.
It's like : "no multiple (something) may be done"
Will this mod solve the problem??
And: where have i to run it?
Thanks in advance.
PS Jeepaholics, i am one of your members, u have one of the best jeep-page in the world

www.jeeptelevision.com


This is a mod for Microsoft SQL Server, not MySQL, which seems to be the DB you're using. That being the case, this is not a mod for you.


Snitz 3.4 Readme | Like the support? Support Snitz too
Go to Top of Page

Jeepaholic
Average Member

USA
697 Posts

Posted - 01 December 2003 :  11:30:22  Show Profile  Visit Jeepaholic's Homepage
quote:
Originally posted by jeepgen

please, help my sql forum.
When i try to archive, i get an error.
It's like : "no multiple (something) may be done"
Will this mod solve the problem??
And: where have i to run it?
Thanks in advance.
PS Jeepaholics, i am one of your members, u have one of the best jeep-page in the world

www.jeeptelevision.com

Hey! Thanks for the compliment on the site! I'm not sure about the error you're getting, but Rui may be correct...as I don't recognize that error.

The script needs to be run in Microsoft Enterprise Manager or Query Analyzer...with a Microsoft SQL Database.

Al Bsharah
Aholics.com

Jeepaholics Anonymous
Broncoholics Anonymous
Network Insight
Go to Top of Page
Page: of 3 Previous Topic Topic Next Topic  
Previous Page
 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.13 seconds. Powered By: Snitz Forums 2000 Version 3.4.07