I've created a stored procedure to update the TabOrder of the children of a particular Parent:
CREATE PROCEDURE dbo.SortTabs(@ParentID int) AS
--Stop return of row count
SET NOCOUNT ON
DECLARE @Seed int -- Holds lowest TabOrder of child tabs
DECLARE @TempTabs TABLE (TabID int, TabName nvarchar(50), Auto int IDENTITY(0,2), TabOrder int) -- Auto column will be numbered 1,3,5,7,etc.
-- Get current lowest tab ID
SET @Seed = (SELECT TOP 1 TabOrder
FROM Tabs
WHERE ParentID = @ParentID AND IsDeleted = 0
ORDER BY TabOrder ASC)
-- Select child tab details into table variable in alphabetical order
INSERT INTO @TempTabs(TabID, TabName)
SELECT TabID, TabName
FROM Tabs WHERE ParentID = @ParentID
ORDER BY TabName ASC
-- update child TabOrder
UPDATE @TempTabs
SET TabOrder = @Seed + Auto
-- update Tabs table with new TabOrders
UPDATE T
SET T.TabOrder = N.TabOrder
FROM Tabs T JOIN @TempTabs N ON T.TabID = N.TabID
GO
I don't claim this is the best SQL in the world, I'm sure someone can do better.
You can run the procedue by passing the ParentID e.g.:
EXEC SortTabs 168
You can see the effect by running this code before and after the procedure:
SELECT * FROM Tabs WHERE ParentID = 168 ORDER BY TabOrder ASC
This appears to work fine, but you still have to go into the GUI and move at least one page manually for the changes to take effect.
Thanks to these guys: http://www.janetsystems.co.uk/Default.aspx?tabid=71&itemid=184 & http://dnn.bi4ce.com/Forums/tabid/242/forumid/2/postid/52/view/topic/Default.aspx