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)
 Display records and starting from a specific row

Author  Topic 

Gingis
Starting Member

6 Posts

Posted - 2001-10-25 : 16:02:57
I must retrieve some datas from a table (which can contain between 500 and 50 000 results, it depends on the query) and display results in an asp page (25 results per page).

I put the results in an array (with the getrows method) but of course the array must be filled only with 25 values (1-25 for the first page, 26-50 for the second...).

What do you think about this solution :

SELECT top 25 ContactID, firstname, Lastname FROM Contacts JOIN .... WHERE ....
AND contactid not in
(select top 25 contactid from contacts order by contactid)
order by contactid


Thats for the page n°2. For the page n°3 the second clause would be "AND contactid not in
(select top 50 contactid from contacts order by contactid)"...

The only problem : I must execute the query twice bacause of the sub-query, which become costly if the query is complex, even if the execution plan should optimize the second query execution.

Despite this problem, do you think this solution is better than :
1. Open a static cursor for the query
2. fetch absolute on the 25th row (or 50th, or 75th...).
3. fetching 25 times with insertion into a temptable for each row.
4. Retrieving every rows from the temptable.

??

Thanks for you opinions.

Gingis

   

- Advertisement -