SQL Server 分页技术(存储过程)
时间:2021-07-01 10:21:17
帮助过:40人阅读
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 分页技术(存储过程)
标签:code type logs page ges char style arch nbsp