添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

直接上代码

if (exists(select * from  sys.objects where name='GetUserByPage'))
    drop proc GetUserByPage
create proc GetUserByPage
    @pageIndex int,
    @pageSize int
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
exec dbo.GetUserByPage 2,4;