SELECT * FROM (
SELECT row_number() over(order by '排序字段') AS rowNumbers,t.* FROM (
你原来的Sql
) t ) t WHERE t.rowNumbers between 1 AND 10
if (object_id('pro', 'P') is not null) ---存储过程分页
drop proc pro
go
create procedure pro
@pageIndex int, --页码
@pageSize int--页大小
as
declare @startRow int, @endRow int
set @startRow = (@pageIndex - 1) * @pageSize +1
set @endRow = @startRow + @pageSize -1 --@pageindex*@pagesize
select * from (
select *, row_number() over (order by sno asc) as number from student) t
where t.number between @startRow and @endRow;--表名列名作为参数必须拼接执行
go
exec pro 2, 2
go