Idea: Use a cursor to be positioned at each record of the desired page, and then loop from other records of this page.
--PageIndex is the index number of the page you want to get, and the number of records displayed per page.
Create Procedure FetchPage (@PageIndex Smallint, @ PageSize Smallint) AS
Declare @index smallintdeclare @firstrecord smallint
- Set the first record location of the page you want to get
Set @firstrecord = (@ pageindex-1) * @ PageSize 1
- Related Games
Declare Customer_Cursor Scroll Cursor Forselect Customerid, CompanyName, ContactName, Address from Customers Order by CompanyName
Open Customer_Cursor
Fetch Absolute @firstrecord from Customer_Cursor
- Cycle get the remaining record
Set @index = 1WHILE @@ fetch_status = 0 and @index <@pagesize beginfetch next from customer_cursorset @ index = @ index 1nd
Close Customer_Cursordeallocate Customer_cursor
The advantage of using the cursor is to skip the first record of the page and extract the required record. The disadvantage is that multiple record sets will be returned at the same time, while each recordset contains only one record. Solution: You can use DateSet or DataReader to handle each recordset, add all records to a new data container.
As for the memory process, it will not be said in the program.