Click here to Skip to main content
14,735,523 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
hi freinds
i have a table with 250 record , i want select 100th to 200th rows , please guide me.
Posted
Updated 29-May-20 5:50am

If you are using MS SQL Server 2005 and above you can use ROW_NUMBER.

Find out more details here.
Another link.[^]
   
I have one tip posted which lets you select from any range of rows.

Check
How To Select Record Based on Row Number[^]

I hope this will help.
   
Try:
SELECT *
FROM (
     SELECT *, ROW_NUMBER() OVER (ORDER BY OrderID) AS RowNum
     FROM [Order Details]
     ) AS MyDerivedTable
WHERE MyDerivedTable.RowNum BETWEEN 100 AND 200
   
Comments
Suresh Suthar 6-Sep-11 4:40am
   
Nice. 5.
Joezer BH 11-Sep-13 10:52am
   
5ed!

I've just used it as a reference in a solution to the same problem :)
Maddy selva 25-Dec-14 2:59am
   
my 5+
User-12551084 7-Jun-20 14:02pm
   
Nice
Hi,
Use The sql Query like this,
select top(100) ClumnName from Table1 where ClumnName NOT IN (select top (100) ClumnName from Table1 )


I hope this may help you,
Thanks.
   
v2
Comments
Toniyo Jackson 6-Sep-11 6:34am
   
Good answer, 5!
Joezer BH 11-Sep-13 10:50am
   
5ed!

I've just used it as a reference in a solution to the same problem :)
Blesson Mathew 6-Sep-11 8:11am
   
Thaanx Jackson
You can also use Linq-to-SQL for that. It is a case where it is much simpler to express the query in Linq.

var query = 
    from m in dataContext.MyTable
    select m;
var result = query.Skip(100).Take(100);


Or even if you don't use it, you might get LINQPad[^], write a Linq query and then get the generated SQL code...
   
v3
Comments
Simon Bang Terkildsen 6-Sep-11 22:06pm
   
+5 for LINQ, learn it and love it :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900