DhruvJoshi
DhruvJoshi

Reputation: 17146

How to do paging in MS SQL query?

What is the easiest way for paging in MS SQL? I have tried nested queries where I select TOP results and then reverse order and select TOP in the result again. But is there any way like LIMIT in MySQL?

Upvotes: 0

Views: 126

Answers (2)

SAS
SAS

Reputation: 4045

Simple example:

DECLARE @OffsetRows tinyint = 0
, @FetchRows tinyint = 20;

SELECT Id, Data, Date
FROM MyTable
ORDER BY Date
OFFSET @OffsetRows ROWS
FETCH NEXT @FetchRows ROWS ONLY;

Upvotes: 1

Ravi Verma
Ravi Verma

Reputation: 184

Please try OFFSET FETCH clause of MS SQL Server 2012 . See link http://technet.microsoft.com/en-us/library/gg699618.aspx

Upvotes: 2

Related Questions