直接上代码
if (exists(select * from sys.objects where name='GetUserByPage')) drop proc GetUserByPage go create proc GetUserByPage @pageIndex int, @pageSize int as declare @startIndex int, @endIndex int; set @startIndex = (@pageIndex-1)*@pageSize+1; set @endIndex = @startIndex + @pageSize -1 ; begin select Id,Name from ( select *,row_number()over (order by Id)as number from UserInfo )t where t.number>=@startIndex and t.number<=@endIndex end go exec dbo.GetUserByPage 2,4;