|
I have almost 1 mill roes and he size keeps growing. In order not to delay the query I need to display Top 100 followed by 101-200 followed by 201 -300 etc.I am not loading all the data at one time .I need the 100 rows first and then on button click retrieve the next 100 and so on .I have to dispay the data in a single view so paging is not allowed in the grid.Thank you !
(comments are locked)
|
|
In SQL 2008, you can use a cte and rownumber to get the records in batches of x records. See the sample below: In SQL 2012, you can use OFFSET in the order by clause, without the need for the CTE and rownumber.
(comments are locked)
|
|
In addition to @Håkan Winther's answer, you might want to have a read of Dave Ballantyne's blog on the subject.
(comments are locked)
|


Just a comment... While the business requirement may be to return all 1 million rows, processing millions of rows, even using some of the efficient operations suggested below, is a bad design. You need to push back on the business requirement and get them to define some mechanisms of filtering the data first. Trust me, no one ever reads millions of rows. They just want to know that the data is there. You should never try to return it to them all at once.