sql server 2005中row_number实现分页的例子

发布时间:2019-07-30编辑:脚本学堂
sql server 2005中row_number实现分页,分为二种方式,即使用between方式与top方式。

供大家学习参考。

复制代码 代码示例:

---row_number分页实例
---by http://www.jb200.com
declare @PageNumber int
declare @PageSize int

set @PageNumber=2
set @PageSize=20

--使用between方式
select *
from
(
select
row_number() over (order by source_ip,id) as row_num,
* from tb_test_news) as page_table
where row_num between (@PageNumber - 1) * @PageSize + 1 and @PageNumber * @PageSize

--保用top方式
select top 20 *
from
(
select
row_number() over (order by source_ip,id) as row_num,
* from tb_test_news
) as page_table
where row_num > (@PageNumber - 1) * @PageSize
order by row_num