Information générale
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
Précédent
Suivant
Répondre
Voir le fil de ce thread
Voir le fil de ce thread à partir de ce message seulement
Voir tous les messages de ce thread
Voir tous les messages de ce thread à partir de ce message seulement