sqlserver使用窗口函数实现分页
发布时间:2015-06-05 来源:查字典编辑
摘要:sqlserver使用窗口函数实现分页ALTERPROC[dbo].[usp_GetStuPage]@pageIndexINT=1,--当前...
sqlserver使用窗口函数实现分页
ALTER PROC [dbo].[usp_GetStuPage]
@pageIndex INT =1,--当前页码
@pageSize INT =10,--页容量
@pageCount int OUTPUT--输出总页数
AS
BEGIN
SELECT @pageCount=CEILING((COUNT(id)*1.0)/@pageSize) FROM StudentsInfo
SELECT * FROM (
SELECT *,ROW_NUMBER() OVER(ORDER BY id) AS rownum FROM StudentsInfo
)AS t WHERE t.rownum BETWEEN (@pageIndex-1)*@pageSize+1 AND @pageIndex*@pageSize
END