短小精悍的分页过程


CREATE Procedure prGetRecordByPage
(
@PageSize int, –每页的记录条数
@PageNumber int, –当前页面
@QuerySql varchar(1000),–部分查询字符串,如* From Test order by id desc
@KeyField varchar(500)
)
AS
Begin

Declare @SqlTable AS varchar(1000)
Declare @SqlText AS Varchar(1000)

Set @SqlTable='Select Top '+CAST(@PageNumber*@PageSize AS varchar(30))+' '+@QuerySql
Set @SqlText='Select Top '+Cast(@PageSize AS varchar(30))+' * From '
+'('+@SqlTable+') As TembTbA '
+'Where '+@KeyField+' Not In (Select Top '+CAST((@PageNumber-1)*@PageSize AS varchar(30))+' '+@KeyField+' From '
+'('+@SqlTable+') AS TempTbB)'
Exec(@SqlText)

End
GO

Share

发表评论

电子邮件地址不会被公开。 必填项已用*标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据