一:row_number方法分页

string Sql="select * from (select row_number() over (order by created) as row_number,* from contents) as T where T.row_number>"+(pagenumber-1)*pagesize+"and T.row_number<="+pagenumber*pagesize:
其中contents为表名,pagenumber为当前显示的页号,pagesize为每页显示的数据条数!

=====================================================================================

二:Sql自定义方式分页

declare@pageIndexint

declare@startRowIndexint
declare@maximumRowsint

set@pageIndex=5

set@startRowIndex=0
set@maximumRows=1000

set@startRowIndex=(@pageIndex-1)*@maximumRows+1

select ProductID,ProductName,AuthorNames,ManufacturerName,RowRank
from (
select ProductID,ProductName,AuthorNames,ManufacturerName,row_number() over(orderby ProductID) as RowRank
from Products
)
as ProductsWithRowNumbers
where RowRank >=@startRowIndex
and RowRank < (@startRowIndex+@maximumRows)
posted on 2011-02-18 15:15  高兴happy  阅读(447)  评论(0编辑  收藏  举报