 )
 AS
 begin
-   declare @post_totalrowsnumber int 
-   declare @firstselectrownum int   
-   declare @firstselectposted datetime
-   declare @ceiling decimal  
-   declare @offset int 
-
-    set nocount on	
-
-    -- find total returned count
-        select
-        @post_totalrowsnumber = COUNT(c.TopicID)
-    FROM [{databaseOwner}].[{objectQualifier}Topic] c JOIN [{databaseOwner}].[{objectQualifier}User] b 
-        ON b.UserID=c.UserID 
-    JOIN [{databaseOwner}].[{objectQualifier}Forum] d 
-        ON d.ForumID=c.ForumID
-    WHERE c.ForumID = @ForumID
-        AND  c.Priority=2 
-        AND	c.IsDeleted=0
-        AND	(c.TopicMovedID IS NOT NULL OR c.NumPosts > 0) 
-        AND
-        ((@ShowMoved = 1)
-        or
-        (@ShowMoved <> 1 AND  c.TopicMovedID IS NULL))
-
-      select @PageIndex = @PageIndex+1;
-      select @firstselectrownum = (@PageIndex - 1) * @PageSize + 1 
-        -- find first selectedrowid 
-   if (@firstselectrownum > 0)   
-   set rowcount @firstselectrownum
-   else
-   -- should not be 0
-   set rowcount 1
-    
-   select		
-        @firstselectposted = c.LastPosted
-    from
-    [{databaseOwner}].[{objectQualifier}Topic] c 
-    JOIN [{databaseOwner}].[{objectQualifier}User] b 
-        ON b.UserID=c.UserID 
-    JOIN [{databaseOwner}].[{objectQualifier}Forum] d 
-        ON d.ForumID=c.ForumID
-    WHERE c.ForumID = @ForumID
-        AND  c.Priority=2 
-        AND	c.IsDeleted=0
-        AND	(c.TopicMovedID IS NOT NULL OR c.NumPosts > 0) 
-        AND
-        ((@ShowMoved = 1)
-        or
-        (@ShowMoved <> 1 AND  c.TopicMovedID IS NULL))		
-    order by
-         c.Priority DESC,	c.LastPosted DESC		
-    
-    set rowcount @PageSize	
-
-    select
-    c.ForumID,
+   declare @TotalRows int
+   declare @FirstSelectRowNumber int
+   declare @LastSelectRowNumber int
+   
+   -- find total returned count
+   select  @TotalRows = COUNT(c.TopicID)
+   FROM [{databaseOwner}].[{objectQualifier}Topic] c 
+   WHERE c.ForumID = @ForumID
+   AND	c.[Priority] = 2
+   AND	c.IsDeleted = 0
+    AND	(c.TopicMovedID IS NOT NULL OR c.NumPosts > 0) 
+	AND
+	(@ShowMoved = 1 or (@ShowMoved <> 1 AND  c.TopicMovedID IS NULL))
+	
+	select @PageIndex = @PageIndex+1;
+	select @FirstSelectRowNumber = (@PageIndex - 1) * @PageSize + 1;
+	select @LastSelectRowNumber = (@PageIndex - 1) * @PageSize + @PageSize;
+	
+	with TopicIds  as
+	 (
+	 select ROW_NUMBER() over (order by tt.[Priority] desc,tt.LastPosted desc) as RowNum, tt.TopicID
+	 from  [{databaseOwner}].[{objectQualifier}Topic] tt
+	 where tt.ForumID = @ForumID and tt.[Priority] = 2
+	  AND	tt.IsDeleted = 0
+	  AND	((tt.TopicMovedID IS NOT NULL) OR (tt.NumPosts > 0))
+	  AND
+	  (@ShowMoved = 1 or (@ShowMoved <> 1 AND  TopicMovedID IS NULL))
+	  )	  
+	  select
+		    c.ForumID,
             c.TopicID,
             c.Posted,
             LinkTopicID = IsNull(c.TopicMovedID,c.TopicID),

    @FindLastRead bit = 0
)
AS
begin
   declare @post_totalrowsnumber int 
   declare @TotalRows int
   declare @FirstSelectRowNumber int
   declare @LastSelectRowNumber int
   
   -- find total returned count
   select  @post_totalrowsnumber = COUNT(c.TopicID)
   FROM [{databaseOwner}].[{objectQualifier}Topic] c 
   WHERE c.ForumID = @ForumID
   AND	((c.Priority = 1) OR (c.Priority <=0 AND c.LastPosted>=@Date )) 

			BannedIps c
			inner join [{databaseOwner}].[{objectQualifier}BannedIP] a	
			on 	c.Mask = a.Mask	
			where c.RowNum between (@FirstSelectRowNumber) and (@LastSelectRowNumber)
			order by c.RowNum asc
  end
  else
