码迷,mamicode.com
首页 > 数据库 > 详细

sql server 存储过程分页

时间:2015-09-10 15:48:30      阅读:162      评论:0      收藏:0      [点我收藏+]

标签:

create proc [dbo].[sp_GetPagedList]
(
@pageIndex int,
@pageSize int,
@orderBy nvarchar(512),
@columns varchar(512) ,
@tableName varchar(512),
@where nvarchar(max)
)
AS
begin
declare @sql nvarchar(max)
declare @currPage int
set @currPage=@pageIndex*@pageSize
set @sql=‘
select count(*) from (
select ROW_NUMBER() over (order by ‘+@orderBy+‘ desc) as rowid,‘+@columns+‘ from ‘+@tableName+‘ where 1=1 ‘+
@where+‘
) temp ‘
 
exec(@sql)
set @sql=‘
select * from (
select ROW_NUMBER() over (order by ‘+@orderBy+‘ desc) as rowid,‘+@columns+‘ from ‘+@tableName+‘ where 1=1 ‘+
@where+‘
) temp where rowid between ‘+Convert(varchar(50),@currPage-@pageSize+1)+‘ and ‘+Convert(varchar(50),@currPage)
exec(@sql)
end

sql server 存储过程分页

标签:

原文地址:http://www.cnblogs.com/symcious/p/4798002.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!