可用。儲存分頁

lanchengxiaoxiao發表於2012-05-04
USE [Studentnew]
GO
/****** Object:  StoredProcedure [dbo].[pageYe]    Script Date: 05/04/2012 16:37:51 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

ALTER procedure [dbo].[pageYe]
@PageIndex int,--頁面索引計數,計數0為第一頁。
@PageSize int,--每個頁面顯示大小
@RecordCount int output,
@PageCount int output --頁數
as
/*獲取記錄數*/
Select @RecordCount = COUNT(*) FROM a
/*計算頁面資料*/
SET @PageCount = CEILING(@RecordCount * 1.0 / @PageSize)
---
Select SerialNumber,id,Name FROM
(Select id,Name,ROW_NUMBER() OVER (ORDER BY id DESC) AS SerialNumber
FROM a) AS T
Where T.SerialNumber > (@PageIndex * @PageSize)  
and T.SerialNumber <= ((@PageIndex+1) * @PageSize)
/*****
declare @RecordCount int, @PageCount int
exec pageYe 0,3,@RecordCount output,@PageCount output
print '總記錄數'+ cast(@RecordCount as varchar(100))--拼接字串要把整型轉換為字串

print '總頁數'+convert(varchar(100),@PageCount)

*****/

相關文章