select range of data rows in MSSQL2005

We all know if we have to find range of data then we use sub queries but sql2005 provide row_number to find range of data

for ex.
if we have to select data from 21 row to 30 the n

SELECT * FROM
(
SELECT Row_Number() OVER (ORDER BY last_name, first_name) as rowid,
user_id,
last_name,
first_name
FROM user
) as a
where rowid >20 and rowid <31

same if i want 28 record the n

SELECT * FROM
(
SELECT Row_Number() OVER (ORDER BY last_name, first_name) as rowid,
user_id,
last_name,
first_name
FROM user
) as a
where rowid = 28

Leave a Reply

I'm Yogesh Kadvekar, a Technology Consultant, Computer Engineer by education, tech writer and problem solver. I love startups. I love hiking, sports, arts and Stock market. Say hello!

%d bloggers like this: