数据库分页存储过程
- 作者:zhaozj
- 发表时间:2020-12-23 11:00
- 来源:未知
/*数据库分页存储过程---equn.net参数说明:?tablename为搜索表名?where为搜索表名,要显示所有记录请设为"1=1"?orderby为搜索结果排序,如order by id desc?curpage当前页码?page_record每页记录条数结果:?返回表tablename中满足条件where的第curpage页的page_record条记录,结果按orderby排序*/ CREATE PROCEDURE Xp_Page(@tablename varchar(50),@where varchar(100),@orderby varchar(100),@curpage int,@page_record int) ?AS begin ?declare @cmd varchar(500) ?declare @uprecord int ?set @uprecord=@curpage * @page_record ?set @cmd='select top '+cast(@page_record as char)+' * from '+@tablename+' where '+@where+' and id not in (select top '+cast(@uprecord as char)+' id from '+@tablename+' where '+@where+' '+@orderby +') '+@orderby ?exec(@cmd) end GO