Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Block of records and sorting

Author  Topic 

kensai
Posting Yak Master

172 Posts

Posted - 2002-08-04 : 07:20:06
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=25
as
set nocount on

declare @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_LastReplyTime
from 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 @sql

go


   

- Advertisement -