翻页存储过程CREATE PROCEDURE [Page] 
翻页存储过程
翻页存储过程
AS
翻页存储过程
--无优化倒序
翻页存储过程
declare @pageSize int   --返回一页的记录数
翻页存储过程
declare @CurPage int  --页号(第几页)0:第一页;-1最后一页。
翻页存储过程
declare @Count int
翻页存储过程
declare @id int
翻页存储过程
翻页存储过程
set @pageSize=10
翻页存储过程
set @CurPage =1
翻页存储过程
翻页存储过程
翻页存储过程
--定位
翻页存储过程
if @CurPage = -1
翻页存储过程
begin
翻页存储过程 
--最后一页
翻页存储过程
set rowcount @pageSize
翻页存储过程
select @id = ProductID from Products   order by ProductID
翻页存储过程
end
翻页存储过程
翻页存储过程
if @CurPage > 0
翻页存储过程
begin
翻页存储过程 
set @Count = @pageSize * (@CurPage -1+ 1
翻页存储过程 
set rowcount @Count
翻页存储过程 
select @id = ProductID from Products   order by ProductID desc
翻页存储过程
end
翻页存储过程
翻页存储过程
--返回记录
翻页存储过程
set rowcount @pageSize
翻页存储过程
select * from Products   where ProductID <=@id order by ProductID desc
翻页存储过程
翻页存储过程
set rowcount 0
翻页存储过程
GO 
翻页存储过程
翻页存储过程

相关文章: