萬盛學電腦網

 萬盛學電腦網 >> 數據庫 >> mssql數據庫 >> sqlserver使用窗口函數實現分頁

sqlserver使用窗口函數實現分頁

   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

copyright © 萬盛學電腦網 all rights reserved