代码
create proc sp_pagingwithproc
@page int
as
declare @count int
set @count = (select count(0) from testtable)
select top 5 b.*
from (
select top (@count - 5*@page) indexcloumn
from testtable
order by indexcloumn desc) a,testtable b
where b.indexcloumn = a.indexcloumn
order by a.indexcloumn
@page int
as
declare @count int
set @count = (select count(0) from testtable)
select top 5 b.*
from (
select top (@count - 5*@page) indexcloumn
from testtable
order by indexcloumn desc) a,testtable b
where b.indexcloumn = a.indexcloumn
order by a.indexcloumn
@page 页码,0开始
@count 该表一共存在的纪录数
@testtable 表名
@indexcloumn 排序列