OK so I solved my own problem - below is a fix for the Forum_SearchGetResults script. The original attempted to order by on a column that is not part of the select statement - the original script worked ok on my test box but not on my isp's server.
There were also 2 PRINT statements commented out that I highly recommend NEVER leaving in production code - I will sometimes surround prints with a @verbose check or something so they dont fire unless that parm has a value etc.... other wise I always try to remember to remove them.
The stuff I did is bolded.
ALTER PROCEDURE [yourid].[Forum_SearchGetResults]
(
@Filter nvarchar(500),
@PageIndex int,
@PageSize int,
@UserID int,
@ModuleID int,
@FromDate datetime,
@ToDate datetime
)
AS
-- Create a temp table to store the select results
CREATE TABLE #PageIndex
(
IndexID int IDENTITY (1, 1) NOT NULL,
ThreadID int
)
-- Create dynamic SQL to populate temporary table
DECLARE @sql nvarchar(2000)
SELECT @sql = 'INSERT INTO #PageIndex(ThreadID) SELECT DISTINCT(P.ThreadID) ' +
--SELECT @sql = 'INSERT INTO #PageIndex(ThreadID) SELECT DISTINCT (P.ThreadID) CreatedDate ' +
'FROM Forum_Posts P ' +
'INNER JOIN Forum_Threads T ON P.ThreadID = T.ThreadID ' +
'INNER JOIN Forum_Forums F ON T.ForumID = F.ForumID ' +
'INNER JOIN Forum_Groups G ON F.GroupID = G.GroupID ' +
'INNER JOIN Forum_Posts LP ON T.ThreadID = LP.ThreadID ' +
'WHERE P.ThreadID = T.ThreadID AND ' +
'T.ForumID = F.ForumID AND ' +
'F.GroupID = G.GroupID ' +
'AND P.[CreatedDate] > ''' + CONVERT(varchar, @FromDate) + ''' ' +
'AND P.[CreatedDate] < ''' + CONVERT(varchar, @ToDate) + ''' ' +
'AND P.IsApproved = 1 ' +
'AND P.IsLocked = 0 ' +
'AND G.ModuleID = ' + CONVERT(varchar, @ModuleID) + ' AND ' +
'( F.ForumID NOT IN (SELECT ForumID FROM Forum_PrivateForums) OR ' +
' F.ForumID IN ( ' +
'SELECT ForumID ' +
'FROM Forum_PrivateForums (nolock) ' +
'WHERE (RoleID IN (SELECT RoleID FROM UserRoles WHERE UserID = ' + CONVERT(varchar, @UserID) + ' ) ' +
'OR EXISTS (SELECT TOP 1 1 FROM Users WHERE UserID = ' + CONVERT(varchar, @UserID) + ' and IsSuperUser=1)))) ' +
@Filter + ' GROUP BY P.ThreadID , P.CreatedDate' -- ORDER BY P.CreatedDate DESC '
--Print @sql
EXEC(@sql)
-- All of the rows are inserted into the table - now select the correct subset
DECLARE @PageLowerBound int
DECLARE @PageUpperBound int
DECLARE @RecordCount int
-- Set the page bounds
SET @PageLowerBound = @PageSize * @PageIndex
SET @PageUpperBound = @PageLowerBound + @PageSize + 1
SELECT @RecordCount = COUNT(*) FROM #PageIndex
--Print @RecordCount
-- Select the data out of the temporary table
-- Select the data out of the temporary table
SELECT
PageIndex.ThreadID,
P.[Subject],
P.[CreatedDate],
FU.[UserID],
FU.[Alias],
T.[ForumID],
T.[Replies],
T.[Views],
F.[Name] As ForumName,
RecordCount = @RecordCount,
(SELECT Count([ThreadID]) FROM Forum_ThreadRating WHERE ThreadID = PageIndex.ThreadID) As RatingCount,
(SELECT AVG([Rate]) FROM Forum_ThreadRating WHERE ThreadID = PageIndex.ThreadID) As Rating,
(SELECT Distinct Count(UserID) FROM Forum_ThreadsRead WHERE ForumID = T.[ForumID] AND UserID = FU.[UserID] AND P.[CreatedDate] > LastPurseDate AND ReadThreads NOT LIKE '%' + CONVERT(varchar, PageIndex.ThreadID) + ';%') As IsUnRead
FROM
Forum_Posts P
INNER JOIN Forum_Threads T ON P.ThreadID = T.ThreadID
INNER JOIN Forum_Forums F ON T.ForumID = F.ForumID
INNER JOIN Forum_Users FU ON P.UserID = FU.UserID, #PageIndex PageIndex
WHERE
PageIndex.IndexID > @PageLowerBound AND
PageIndex.IndexID < @PageUpperBound AND
PageIndex.ThreadID = P.ThreadID AND
FU.[UserID] = P.[UserID] AND
P.[ThreadID] = T.[ThreadID] AND
P.[CreatedDate] > @FromDate AND
P.[CreatedDate] < @ToDate AND
T.[ForumID] = F.[ForumID] AND
(P.[CreatedDate] = (SELECT MAX([CreatedDate]) FROM Forum_Posts WHERE ThreadID = PageIndex.ThreadID)) AND
(F.ForumID NOT IN (SELECT ForumID FROM Forum_PrivateForums) OR
F.ForumID IN (
SELECT ForumID
FROM Forum_PrivateForums
WHERE (RoleID IN (SELECT RoleID FROM UserRoles WHERE UserID = @UserID)
OR EXISTS (SELECT TOP 1 1 FROM Users WHERE UserID = @UserID and IsSuperUser=1))))
ORDER BY
P.[CreatedDate] DESC