Hi,
I was looking at the Forum Database structure and found this Stored Procedure.
This was very strnge to NOTE that there has been a condition check where you checked for Thread Existense based on :
FP.PostID = T.ThreadID
The above text was taken from the Dynamic SQL generated Inside this Stored Procedure: [Forum_Thread_GetAll]
Actual full content is this:
-- Create dynamic SQL to populate temporary table
SELECT @sql = 'INSERT INTO #PageIndex (ThreadID)' + ' SELECT T.ThreadID' + ' FROM {databaseOwner}{objectQualifier}Forum_Threads T' + ' WHERE T.ThreadID IN' +
' (SELECT TOP ' + CONVERT(VARCHAR, @PageSize) + ' T.ThreadID' + ' FROM {databaseOwner}{objectQualifier}Forum_Threads T' +
' INNER JOIN {databaseOwner}{objectQualifier}Forum_Posts FP ON T.ThreadID = FP.ThreadID' + ' INNER JOIN {databaseOwner}{objectQualifier}Forum_Posts LP ON T.ThreadID = LP.ThreadID' +
' INNER JOIN {databaseOwner}{objectQualifier}Forum_Forums F ON T.ForumID = F.ForumID' + ' INNER JOIN {databaseOwner}{objectQualifier}Forum_Groups FG ON F.GroupID = FG.GroupID' +
' WHERE FG.ModuleID = ' + CONVERT(VARCHAR, @ModuleID) + ' AND (T.ForumID = ' + CONVERT(VARCHAR, @ForumID) + ' OR (' + CONVERT(VARCHAR, @ForumID) + ' = -1 AND F.PublicView = 1 AND T.IsPinned = 0))' +
' AND LP.PostID = T.LastPostedPostID AND FP.PostID = T.ThreadID' +
' AND (FP.IsApproved = 1) AND (FP.IsLocked = 0) ' + @Filter + ' AND T.ThreadID NOT IN' +
' (SELECT TOP ' + CONVERT(VARCHAR, @PageLowerBound) + ' T.ThreadID' +
' FROM {databaseOwner}{objectQualifier}Forum_Threads T' +
' INNER JOIN {databaseOwner}{objectQualifier}Forum_Posts FP ON T.ThreadID = FP.ThreadID' +
' INNER JOIN {databaseOwner}{objectQualifier}Forum_Posts LP ON T.ThreadID = LP.ThreadID' +
' INNER JOIN {databaseOwner}{objectQualifier}Forum_Forums F ON T.ForumID = F.ForumID' +
' INNER JOIN {databaseOwner}{objectQualifier}Forum_Groups FG ON F.GroupID = FG.GroupID' +
' WHERE FG.ModuleID = ' + CONVERT(VARCHAR, @ModuleID) +
' AND (T.ForumID = ' + CONVERT(VARCHAR, @ForumID) + ' OR (' + CONVERT(VARCHAR, @ForumID) + ' = -1 AND F.PublicView = 1 AND T.IsPinned = 0))' +
' AND LP.PostID = T.LastPostedPostID AND FP.PostID = T.ThreadID' +
' AND (FP.IsApproved = 1) AND (FP.IsLocked = 0) ' + @Filter +
' ORDER BY T.IsPinned DESC, LP.CreatedDate DESC)' + ' ORDER BY T.IsPinned DESC, LP.CreatedDate DESC)'
EXEC ( @sql )
Please guide me why this Check has been placed I'm really unable to understand that. Don't you think it should be this: FP.ThreadID = T.ThreadID
Thanks.