Good morning
I have a forum setup something like
Category
Forum 1
Forum 2
Sub
Forum 1
Sub
Forum 2
……………
Sub
Forum 20
I want to add Sub Forums frequently but I want them to show
in alphabetic order.
Unless I am missing something I can’t drag and drop the sub
forum in the page admin_view_forums.asp.
If I were to add a new sub forum that is to go before Sub
Forum 2 for example I wanted to avoid having to update the order combo box for Sub Forum
3 -20 or possibly higher?
I did knock up the following query and it seems to work, but
an official button would be nicer. J
DECLARE @ParentForumID INT
DECLARE @ParentForumOrder INT
-- Find the Forum ID for the forum that I want to order the sub forums for
SELECT @ParentForumID = Forum_ID,
@ParentForumOrder = Forum_order
FROM dbo.tblForum
WHERE Forum_Name = Forum 2';
-- Make the forum order 1,2,3 etc based on the alphabetical order plus the forum_order of the parent
WITH NewValues AS
(
SELECT Forum_ID, ROW_NUMBER() OVER (ORDER BY Forum_Name ASC) + @ParentForumOrder AS NewForumOrder
FROM dbo.tblForum
WHERE Sub_id = @ParentForumID
)
UPDATE dbo.tblForum
SET Forum_Order = NewValues.NewForumOrder
FROM NewValues
JOIN dbo.tblForum
ON NewValues.Forum_ID = dbo.tblForum.Forum_ID;
I realise that if I had a Forum 3 the above would make the
last Sub Forum Forum_Order the same as the Forum Order for Forum 3, but I don’t
have a forum 3 so am willing to accept it.
Does anyone know of a reason why I shouldn’t do this?
Kind regards
Ian Smith