Sqlserver-dba.com

SQL Pagination

Pagination is a regular technique used for developing web applications. There are numerous methods of implementing pagination . Below, I'm creating  a list of methods that will allow both a SQL Server developer  and  web developer.

Method 1

/**Replace X & y with relevant numbers

**/

SELECT * FROM (
SELECT TOP x * FROM (
SELECT TOP y fields
FROM table
WHERE conditions
ORDER BY table.field  ASC) as foo
ORDER by field DESC) as bar
ORDER by field ASC

Author: Jack Vamvas (http://www.sqlserver-dba.com)

Verify your Comment

Previewing your Comment

This is only a preview. Your comment has not yet been posted.

Working...
Your comment could not be posted. Error type:
Your comment has been posted. Post another comment

The letters and numbers you entered did not match the image. Please try again.

As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.

Having trouble reading this image? View an alternate.

Working...

Post a comment


sqlserver-dba.com | SQL Server Performance Tuning | SQL Server DBA:Everything | FAQ | Contact