create proc sp_proInfo_paging
(@pageSize int=7 ,
@pageNo int=1
)
as
begin
declare @totalCount int
set @totalCount
=(select COUNT(*)
from PROJECT_INFO)
if @pageNo > CEILING(@totalCount*1.0/@pageSize)
begin
set @pageNo =@pageNo %@pageSize
if @pageNo = 0
begin
set @pageNo=1
end
end
;with temp
as
(
select ROW_NUMBER() over(order by p.PROJECT_ID ) as rowNo,p.* from PROJECT_INFO p
)
select * from temp
where temp.rowNo>(@pageNo-1)*@pageSize and temp.rowNo<=@pageNo*@pageSize
order by temp.rowNo
end