I have to make a view in an application for a table that has many hundred thousand records. For obvious reasons, I don’t want to retrieve them all at once.
The convention is to make stored procedures to query the database tables, so my plan was to make a stored procedure to return an interval of records (like records 2000 to 3000). I know the trick to use a nested query to retrieve a range of records with TOP, but as far as I can tell, you can’t parametrize the argument to TOP.
This will be used in conjunction with datasets and DataTables in a C# application.
How should I do this?
You can take advantage of ROW_NUMBER in SQL Server 2008. Below query will returns only 10 rows based on row number.