Saturday, 5 July 2014

Paging in SQL Server

Paging is one the functionality which we can achieved in many ways. So many plugins,technologies used for development.

My sir already used in 2008, I think over to tried it in by different way. It found that Microsoft provides pagination feature with SQL Server 2012. We can acheived it by row_number() and minimum ids etc But from SQL Server 2012 we can do pagination by using FETCH and OFFSET.

From above records, I need to split next 6 records after 32 Address ID.
So doing pagination is a two-step process: -
  • First mark the start of the row by using “OFFSET” command.
  • Second specify how many rows you want to fetch by using “FETCH” command.

Query : 
1. Fetching records from 0 to above

SELECT * FROM [Address] 
order by AddressID
offset 0 rows – start from zero
Fetch Next 6 Rows only

2. Fetching records from 32 to next 6 records paging.

SELECT * FROM [Address] 
order by AddressID
offset 6 rows 
Fetch Next 6 Rows only

[Still reading regarding same... but you can start reading regarding FETCH and OFFSET ]

No comments:

Post a Comment