I have a SQL statement which returns a number of rows and these are inserted into an array within VBA. I then loop through the array and paste into spreadsheet rows.
I am running out of memory, therefore I would like to do the pasting in batches.
I do not mind running the same SQL query each time to collect the data, so long as I can avoid the memory problems. How can I do this? In My SQL I used to use LIMIT, but here I want to say select the first… 1000? and then the next 1000 etc
I’ve found it easiest to create a stored proc to call that uses a basic pagination function by passing in 2 parameters: the rows per page and requested page.
Check out this question: How to do pagination in SQL Server 2008
If you’re calling the stored proc programmatically, you can use a while loop until you don’t get any results back.