sqlserver分頁的兩種寫法分離引見。本站提示廣大學習愛好者:(sqlserver分頁的兩種寫法分離引見)文章只能為提供參考,不一定能成為您想要的結果。以下是sqlserver分頁的兩種寫法分離引見正文
第一種是最傳統的寫法,用存儲進程中的變量作為分頁的乘數
[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