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)
 temp tableless paging, with other order by

Author  Topic 

urbanzen
Starting Member

1 Post

Posted - 2006-06-22 : 05:55:28
Hello SQLteam,

The subject was too short for me to be descriptive in regards of my question, I apologise..

For SQL 2000 on a win2k SP2, I am paginating my result using the rowcount method of controlling my result pages, and forgoing temporary tables or table variables.

Pagination works fine, if in the order by clause there is only 1 constraint, however, I am trying to achieve the effect of ranking by first membership, then the ID of each item. While IDcode is unique, membership has probably 5 distinct choices, and is in a different table so I couldn't combine indexes (and I don't think it helps either?)

If I were to page 3 records at a time, 1st run I would get
Gold    GGG
Gold FFF
Silver AAA


And 2nd run I would get
Gold    GGG
Gold FFF
Silver BBB


instead of the
Silver  AAA
Silver BBB
Silver CCC


intended by pagination.

If it was without the membership column, pagination would be very simple in this case, but what if an order by is required before the paging column?


<pseudocode below>

SET ROWCOUNT @startRowIndex
select @first_id = idcode from pseudotable order by membership, idcode


SET ROWCOUNT @NumRowsToBeFetched
select * from pseudotable where idcode >=@first_id order by membership,idcode


pseudotable
Gold GGG
Gold FFF
Silver AAA
Silver BBB
Silver CCC

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2006-06-22 : 22:06:25
See: http://weblogs.sqlteam.com/jeffs/archive/2003/12/22/672.aspx

for paging using this technique with multiple columns.
Go to Top of Page
   

- Advertisement -