create proc [dbo].[messageMgr] @pageSize int, @pageIndex int, @rcount bigint output--输出查询总记录数 as begin declare @startRowNum int; declare @endRowNum int; set @startRowNum=@pageSize*(@pageIndex - 1)+1; set @endRowNum=@pageIndex*@pageSize; select * from ( SELECT ROW_NUMBER() over(order by a.short_message_time desc) as number,* FROM short_message_info as a) as a where a.number between @startRowNum and @endRowNum; select @rcount=count(number) from ( SELECT ROW_NUMBER() over(order by a.short_message_time desc) as number,* FROM short_message_info as a) as a end