标签:from 存储过程分页 else ges 使用 arch declare creat select
--通用分页显示存储过程
create proc p_paging
@tableName varchar(8000), --表名、视图名
@indexCol varchar(50) = ‘‘, --标识列名(如:比如主键、标识,推荐使用索引列)
@pageSize int = 10, --页面大小
@pageIndex int = 1, --当前页
@orderCol varchar(100) = ‘desc‘,--排序 (如:id)
@where varchar(max) = ‘1=1‘, --条件
@columns varchar(500) = ‘*‘ --要显示的列
as
declare @sql varchar(max)
declare @sql2 varchar(max)
if @where <> ‘‘
begin
select @sql2=‘select count(‘+@columns+‘) from ‘+@tableName+‘ where ‘+ @where
select @sql=‘select ‘+ @columns+ ‘ from ‘+ @tableName+‘ where ‘+ @where +‘ order by ‘+ (@indexCol)+‘ ‘+@orderCol+‘‘+ ‘ offset ‘ +Convert(varchar(10),((@pageIndex-1)*@pageSize))+ ‘ row fetch next ‘ + Convert(varchar(10),(@pageSize))+ ‘ row only‘
end
else
begin
select @sql2=‘select count(‘+@columns+‘) from ‘+@tableName
select @sql2=‘select count(‘+@columns+‘) from ‘+@tableName
select @sql=‘select ‘+ @columns+ ‘ from ‘+ @tableName+‘ order by ‘+ (@indexCol)+‘ ‘+@orderCol+‘‘+ ‘ offset ‘ +Convert(varchar(10),((@pageIndex-1)*@pageSize))+ ‘ row fetch next ‘ + Convert(varchar(10),@pageSize)+ ‘ row only‘
end
标签:from 存储过程分页 else ges 使用 arch declare creat select
原文地址:https://www.cnblogs.com/yuqianwangnan/p/9381353.html