Related Posts Plugin for WordPress, Blogger...

About

Follow Us

Saturday, 7 February 2015

Introduction: 

Sometimes it is required to show data from specific range of rows in our application from database. Suppose Record No 10-20. We can achieve this by simple SQL query.
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.


SELECT * FROM ( SELECT *, ROW_NUMBER() OVER (ORDER BY EmpId) AS row FROM MyTable) temp
WHERE row >= 10 AND row <= 20


This query will retrieve the records from rows 10 to 20 from your table.
Categories:

0 comments:

Post a Comment