0

Is there a way to query Sql Server 2005 and return out of a 100 records. Records 10 - 20. In other words only 10 rows would be returned. Not the first 10 but the second 10 - 20.

I want to do this in TSQL. This would also be acceptable with NHibernate but ultimatley NHibernate would need to convert the HQL into TSQL. I know its possible to do this from Linq but I want to know whether its possible from TSQL.

Oh btw. This is for optimization purpose. So just like you would return the Max 100 rows. You would return it for the same reason but a subset. Performance is the reason!!

Jonathan
  • 2,318
  • 7
  • 25
  • 44

1 Answers1

1

Try:

http://www.sqlservercurry.com/2009/06/skip-and-take-n-number-of-records-in.html

Thomas Li
  • 3,358
  • 18
  • 14
  • thanks brother, excellent result. Problem is I am doing this for performance reasons and I just think that when you are dealing with thousands of rows it would be to slow. That is the right answer though ... what about performance. Im doing this for performance reasons!! – Jonathan Apr 12 '11 at 19:51
  • @Jonathan Performance is not great using this approach. See http://erikporter.com/Blog/ROW_5F00_NUMBER_28002900_-OVER-Not-Fast-Enough-With-Large-Result-Set for details and another solution. – Thomas Li Apr 12 '11 at 19:58