sql server成千上万记录分页
Create PROCEDURE GetRecordByPage
@tblName varchar(255),–表名
@fldName varchar(255),–排序的字段名
@fldStr varchar(1000)=*,–字段列表
@pagesize int=10,–页的大小
@pageIndex int=1,–页序号,第多少页
@order char(4)=ASC–排序方式
AS
declare @sqlstr varchar(8000)
set @sqlstr=select +rtrim(@fldstr) + from + ( select top +str(@pagesize)+ +rtrim(@fldstr)
set @sqlstr=@sqlstr+ from ( +select top +str(@pagesize*@pageindex)+ +rtrim(@fldstr)
set @sqlstr=@sqlstr+ from +rtrim(@tblName) + order by +rtrim(@fldName)+ ASC ) a
set @sqlstr=@sqlstr+order by +rtrim(@fldName)+ desc+ ) b order by +rtrim(@fldName)+ +rtrim(@order)

–print @sqlstr
execute(@sqlstr)
GO

posted on 2010-04-08 10:49  gaojier  阅读(114)  评论(0编辑  收藏  举报