分页存储过程

create proc usp_getPageData
    @totalCount int output,--总页数
    @pageIndex int ,--当前面索引
    @pageCount int--每一页显示的记录数
as
--获取拥有行号的结果集
--select ROW_NUMBER() over(order by sid) , * from dbo.vw_GetStockInfo
--从拥有行号的结果集中再进行查询,使用行号进行条件的判断:获取结果集
select * from  (select ROW_NUMBER() over(order by sid) id , * from dbo.vw_GetStockInfo) temp
where id between (@pageIndex-1)*@pageCount+1 and @pageIndex*@pageCount
--获取总页数
set @totalCount=CEILING((select count(*) from vw_GetStockInfo) *1.0/@pageCount)
go
欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。如果感觉对您有用,请点击推荐。您的支持,是我的动力!
原文地址:https://www.cnblogs.com/ICE_Inspire/p/4513129.html