本文实例讲述了sql server实现分页的方法。分享给大家供大家参考,具体如下:
declare @index int,@num int
set @index = 1--当前页
set @num = 2--单页包含的行数
--分页1
select top (@num) *
from ppohd
where doccode not in
(
select top (@num * (@index -1)) doccode
from ppohd
order by doccode
)
order by doccode
--分页2
select top (@num) *
from ppohd
where doccode >=
(
select max(doccode)
from
(
select top (@num * (@index - 1) + 1) doccode
from ppohd
order by doccode
) as tb
)
--分页3
select top (@num) *
from
(
select ppohd.doccode as 'mydoccode',row_number() over (order by doccode) as sno,*
from ppohd
) as tb
where tb.sno >= @num * (@index - 1) + 1
--分页4
select *
from
(
select ppohd.doccode as 'mydoccode', row_number() over(order by doccode) as sno,*
from ppohd
) as tb
where tb.sno between (@num * (@index - 1) + 1) and (@num * @index)更多关于SQL Server相关内容感兴趣的读者可查看本站专题:《SQL Server分页技术总结》、《SQL Server查询操作技巧大全》、《SQL Server存储过程技巧大全》、《SQL Server索引操作技巧大全》、《SQL Server常用函数汇总》及《SQL Server日期与时间操作技巧总结》
希望本文所述对大家SQL Server数据库程序设计有所帮助。
您可能感兴趣的文章:高效的SQLSERVER分页查询(推荐)sqlserver2005使用row_number() over分页的实现方法SQL SERVER 2008 中三种分页方法与比较oracle,mysql,SqlServer三种数据库的分页查询的实例真正高效的SQLSERVER分页查询(多种方案)SQL Server 分页查询存储过程代码Sql Server 2012 分页方法分析(offset and fetch)五种SQL Server分页存储过程的方法及性能比较sqlserver分页的两种写法分别介绍sqlserver 通用分页存储过程sqlserver 存储过程分页(按多条件排序)sql server中千万数量级分页存储过程代码sqlserver 高性能分页实现分析SQL Server 分页查询通用存储过程(只做分页查询用)










