Sql Server 페이징 처리
RowNumber() 이용 시
-------------------------------------------------------------------------------------------------------
declare @PageRows INT = 10
declare @PageNo INT = 100
select a.*
from (select *
,row_number() over (order by PostCode) as RowNo
,count(*) over() as totcnt
from PostCode ) a
where RowNo between ((@PageNo-1)*@PageRows)+1 AND @PageRows * @PageNo
Offset fetch 이용 (Sql Server 2012 이상 )
-------------------------------------------------------------------------------------------------------
declare @PageRows INT = 10
declare @PageNo INT = 100
select *
,row_number() over (order by PostCode) as RowNo
,count(*) over() TotCnt
from PostCode
Order by PostCode
offset ((@PageNo-1)*@PageRows) rows fetch next @PageRows rows only
;