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