|
--- Create environment, temporary table #, content omitted
-Establish a unique incremental ID, if any, do not need to establish
select id = identity (int, 1,1), * into ## from #
--Group by increasing sequence
select *, (select isnull (max (id), 0) from ## where id <t.id and field2> t.field2) as page into ### from ## t
--Inquire
declare @page int
set @ page = 1-set the page number
exec ('select * from ### where page = (select top 1 page from (select distinct top' + @ page + 'page from ### order by page) tt order by page desc)')
--result
1 a 1 dd 0
2 a 2 ee 0
3 a 3 ee 0
4 a 4 ee 0
-When set @ page = 2 results
5 a 1 c 4
6 a 2 e 4
7 a 3 NULL 4
-When set @ page = 3 results
8 a 1 8 7
9 a 2 5 7
10 a 2 4 7 |
|