首页 > 代码库 > SQL Server 分页技术(存储过程)

SQL Server 分页技术(存储过程)

alter proc proc_getpage
@tbname varchar(20),
@field varchar(200)=*,
@orderfield varchar(20),
@ordertype char(20)=asc,
@pagesize int ,
@pageindex int,
@strWhere varchar(500)=‘‘
as
begin
declare @sql varchar(max)
if(@strWhere<>‘‘)
set @strWhere= where+@strWhere

set @sql=select * from
(select ROW_NUMBER()over(order by +@orderfield+ +@ordertype+) as pos, +@field+ from +@tbname+ +@strWhere+ )as t
where pos between +str((@pageindex-1)*@pagesize+1)+ and +str(@pagesize*@pageindex)

exec( @sql)

end

 

SQL Server 分页技术(存储过程)