当前位置: 数据库>sqlserver
sql server中分页的两种方法介绍
来源: 互联网 发布时间:2014-08-29
本文导语: sql server传统分页写法与SQL Server2005以后版本的分页语句,感兴趣的朋友可以参考下。 一、传统的写法,用存储过程中的变量作为分页的乘数 代码如下: @pageSize int,@currentPage int as select top (@pageSize) * from student where id not in (s...
sql server传统分页写法与SQL Server2005以后版本的分页语句,感兴趣的朋友可以参考下。
一、传统的写法,用存储过程中的变量作为分页的乘数
代码如下:
@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
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以后版本的分页语句
代码如下:
@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