Tuesday, May 15, 2012

Paging Option in SQL Server 2012


Paging Result Using T-SQL

We need to use OFFSET, FETCH Next Functions inline with Orderby clause to get the pagination in T-SQL

select * from HydStock order by SlNo offset 10 Rows Fetch Next 20 ROWs only
The above query displays resultset starting from 10th row to 20th row

select * from HydStock order by SlNo offset 20 Rows Fetch Next 30 ROWs only
The above query displays resultset starting from 20th Row to 30th row.

In place of numbers we can pass variables also while doing programming.

The above syntax needs to be specified on a column and followed by range. Starting range will be started with Offset ‘N’ ROWS and ends with Fetch Next ‘N’ ROWS Only


No comments: