I've procedure which takes 25 records at a time(thanks to everyone here who helped me on it). The procedure is for a bulletin board I'm coding. The procedure is used to get 25 topics at a time. The 25 record thing is a paging(I didn't want to do it with ASP). The script takes topics, for example 1-25 or 26-50 etc.The script has a order command. The problem is, the order command sorts after it has taken the 25 records. What I want is, the procedure should first sort by date and time columns and then take the defined 25 records. How should I modify it?The sql code is here:create procedure proc_GetTopics@forumNumber int, @LOWER_LIMIT int=0, @UPPER_LIMIT int=25asset nocount ondeclare @sql nvarchar(3000)set @sql='select dbo.[TOPICS].T_ID, dbo.[TOPICS].T_Topic,dbo.[TOPICS].T_PostDate,dbo.[TOPICS].T_LastReplyDate,dbo.[TOPICS].T_LastReplyTimefrom dbo.[TOPICS]where T_ID not in(select top '+convert(varchar, @LOWER_LIMIT)+' T_ID from dbo.[TOPICS] where T_ForumNumber='+convert(varchar, @forumNumber)+' order by T_ID)and T_ID in(select top '+convert(varchar, @UPPER_LIMIT)+' T_ID from dbo.[TOPICS] where T_ForumNumber='+convert(varchar, @forumNumber)+' order by T_ID)and T_ForumNumber='+convert(varchar, @forumNumber)+'order by T_LastReplyDate desc, T_LastReplyTime desc, T_PostDate desc'exec dbo.sp_executesql @sqlgo