第一種是最傳統(tǒng)的寫法,用存儲過程中的變量作為分頁的乘數(shù)
復制代碼 代碼如下:
[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
您可能感興趣的文章:- 高效的SQLSERVER分頁查詢(推薦)
- 真正高效的SQLSERVER分頁查詢(多種方案)
- 分頁 SQLServer存儲過程
- sqlserver 通用分頁存儲過程
- sqlserver 三種分頁方式性能比較[圖文]
- 基于sqlserver的四種分頁方式總結
- sqlserver分頁查詢處理方法小結
- sqlserver 存儲過程分頁代碼
- SQL server分頁的4種方法示例(很全面)