General information
Forum:
Microsoft SQL Server
Thank fgor reply
I understand the way you suggest.
But in that case is not possible to skip from page 1 to page 9
You do not kwon the lastid from page 8
Kind regards
jan
>There's no simple way to do this. But there is a straight forward method. It requires that you track the first and last sorting items and IDs for the current page of rows.
>
>Let's assume that your sorting by name. To move forward by one page:
>
>SELECT TOP 100 *
>FROM thetable
>WHERE name >= LastNameOnPage
>AND id > LastIDOnPage
>ORDER BY name, id ASC
>
>To move back one page:
>
>SELECT TOP 100 *
>FROM thetable
>WHERE name <= FirstNameOnPage
>AND id < FirstIDOnPage
>ORDER BY name, id DESC
>
>This last set will be sorted backwards so you'll have to resort it or you could do something fancy like:
>
>SELECT a.*
>FROM (
> SELECT TOP 100 *
> FROM thetable
> WHERE name <= FirstNameOnPage
> AND id < FirstIDOnPage
> ORDER BY name, id DESC) AS a
>ORDER BY name, id ASC
>
>
>This ought to get you going in the right direction.
>
>-Mike
Previous
Next
Reply
View the map of this thread
View the map of this thread starting from this message only
View all messages of this thread
View all messages of this thread starting from this message only