2楼正解!
给你一个存储过程去调用就可以了
GetPaginationRecord2 'jobs','job_id',4,2,'order by job_desc','job_id>3'
create procedure GetPaginationRecord2
@tableName varchar(50),
@fieldKey varchar(20),---主键
@pageSize int = 10,
@pageIndex int = 1,
@sqlOrder varchar(100) = '',---排序字段(order by fieldName [desc|asc])
@sqlWhere varchar(200) = ''
as
declare @strSQL varchar(5000)
if @sqlWhere != '' ---有查询字符串
begin
set @strSQL = 'select top '+str(@pageSize)+' * from '+@tableName+' '+
'where '+@fieldKey+' not in(select top '+str((@pageIndex-1)*@pageSize)+
' '+@fieldKey+' from '+@tableName+' where '+@sqlWhere+' '+@sqlOrder+') and '+@sqlWhere+
' '+@sqlOrder
end
else --- 无查询字符串
begin
set @strSQL = 'select top '+str(@pageSize)+' * from '+@tableName+' '+
'where '+@fieldKey+' not in(select top '+str((@pageIndex-1)*@pageSize)+
' '+@fieldKey+' from '+@tableName+' '+@sqlOrder+') '+@sqlOrder
end
exec(@strSQL)
drop procedure GetPaginationRecord2