第一種是最傳統的寫法,用存儲過程中的變量作為分頁的乘數
復制代碼 代碼如下:
[c-sharp] view plaincopyprint?create proc p_paged1
@pageSize int,@currentPage int
as
select top (@pageSize) * from student
where id not in
(select top (@pageSize*(@currentPage-1)) id from student)
go
exec p_paged1 2,3
create proc p_paged1
@pageSize int,@currentPage int
as
select top (@pageSize) * from student
where id not in
(select top (@pageSize*(@currentPage-1)) id from student)
go
exec p_paged1 2,3
--SQL Server2005以後的分頁語句
復制代碼 代碼如下:
[c-sharp] view plaincopyprint?create proc p_paged2
@pageStart int, @pageEnd int
as
select * from
(select *,row_number() over(order by id desc) as rnum
from student) t
where t.rnum between @pageStart and @pageEnd
go
exec p_paged2 5,10