Get Range wise Record from SQL DB

Life is 10% what happens to us and 90% how we react to it. If you don't build your dream, someone else will hire you to help them build theirs.

Get Range wise Record from SQL DB

If you want to get rows base on some range from your database table, then use the following query block for the same:

WITH NumberedMyTable AS
(
    SELECT ROW_NUMBER() OVER (ORDER BY g_regno) AS RowNumber, *
    FROM myTable
)
SELECT * FROM NumberedMyTable WHERE RowNumber BETWEEN @FromNum AND @ToNum

Where @FromNum is starting range and @ToNum is the ending number. For example if you want to get row number 51 to 100, Final query will be:

Where @FromNum is starting range and @ToNum is the ending number. For example if you want to get row number 51 to 100, Final query will be:

SELECT * FROM NumberedMyTable WHERE RowNumber BETWEEN 51 AND 100

Tutorials