How to retrieve specific range of rows from SQL Server database table ?

Introduction: In previous article i explained How to select records between specified range in SQL Server? and How to convert/downgrade SQL Server 2012,2008 database to SQL Server 2005 or lower version and Get column values as comma separated list in sql server | Convert column values to row
 Now in this article i will explain How to get/retrieve specific range of rows from SQL Server database table ?.Suppose there are 100 rows in your table and you want to retrieve only specified rows e.g. 10th to 20th. You can do this by using ROW_NUMBER () function provided by Sql server.
Here is the query

SELECT * FROM ( SELECT *, ROW_NUMBER() OVER (ORDER BY EmpId) AS row FROM MyTable) temp
WHERE row >= 10 AND row <= 20
Note: Replace the “EmpId” with your column name(primary key column) and “MyTable” with
your table name. It will retrieve the records from rows 10 to 20 from your table.

Now over to you:
"If you like my work; you can appreciate by leaving your comments, hitting Facebook like button, following on Google+, Twitter, Linked in and Pinterest, stumbling my posts on stumble upon and subscribing for receiving free updates directly to your inbox . Stay tuned and stay connected for more technical updates."

Previous
Next Post »

If you have any question about any post, Feel free to ask.You can simply drop a comment below post or contact via Contact Us form. Your feedback and suggestions will be highly appreciated. Also try to leave comments from your account not from the anonymous account so that i can respond to you easily..