Server Paging in SQL Server 2012

Apart from the previous versions of SQL Server where the paging of result set is obtained using temp tables, ROW_NUMBER() and TOP, SQL Server 2012 provide simple functions for paging result sets. This comes in the form of OFFSET and FETCH.

The given example shows the tricky method used in previous version sql server.

SELECT TOP 10 *
FROM (SELECT ROW_NUMBER() OVER(ORDER BY trx_id) AS row_num,
trx_id,trx_date,item_id,qty,cost
FROM trx_history
) trx WHERE trx.row_num > 20

We can achieve the same result using OFFSET and FETCH, but in more efficient way just like the example given below.

SELECT
trx_id,trx_date,item_id,qty,cost
FROM trx_history
ORDER BY trx_id ASC
OFFSET 20 ROWS FETCH NEXT 10 ROWS ONLY

Ready to Build
Something
Extraordinary?

Join 300+ companies who trust us to turn their biggest ideas into market-leading solutions.

Our Global Team
500+ Engineers Worldwide
SOC 2 Certified

Get in Touch with Us

Our Global Team
500+ Engineers Worldwide
SOC 2 Certified

InApp India Office

121 Nila, Technopark Campus
Trivandrum, Kerala 695581
+91 (471) 277 -1800
mktg@inapp.com

InApp USA Office

999 Commercial St. Ste 210 Palo Alto, CA 94303
+1 (650) 283-7833
mktg@inapp.com

InApp Japan Office

6-12 Misuzugaoka, Aoba-ku
Yokohama,225-0016
+81-45-978-0788
mktg@inapp.com
Terms Of Use
© 2000-2026 InApp, All Rights Reserved