상세 컨텐츠

본문 제목

Sql Server 페이징 처리

DataBase/SQL Server

by 탑~! 2021. 1. 4. 16:05

본문

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
;

 

출처 : https://m.blog.naver.com/supercrat/220670315429

'DataBase > SQL Server' 카테고리의 다른 글

MS SQL Server DB 사용량, Table Size  (0) 2021.01.04
SQL Server Lock 확인 및 IP추적  (0) 2021.01.04
SQL Server 인덱스 리빌드  (0) 2021.01.04
MS SQL Server 테이블 건수 용량 확인 쿼리  (0) 2021.01.04
쿼리 실행 순서  (0) 2021.01.04

관련글 더보기