Paging 分页脚本文件 #sqlserver
----------------------------------分页脚本文件-------------------------------------------
alter procedure table (
@pageIndex int, -- 当前选择的页码
@pageSize int, --单页显示的数据量
@pageCount int out --总的页数
)
as
begin
select * from (select rn=row_number() over (order by Id desc ) * from News ) as tempTable
-----计算 开始读取和结束读取的位置
where tempTable.rn between ((@pageIndex-1)*@pageSize+1) and (@pageIndex * @pageSize)
--------计算 总页数-------
declare @recordCount int
select @recordCount=count(*) from News
set @pageCount=ceiling(@recordCount/(@pageSize*1.0)) ----总页数
end