Using Top Values to export a range of records

jscranton

Well-known Member
Joined
May 30, 2011
Messages
707
I have a very large table of 3 million records that I need to export out of ACCDB in chunks of 500k records at a time.

They are sorted in a particular order so their Primary IDs are not sequential.

I can easily export out the first 500k by setting the Top Values property to 500,000. Is there a way to then set the range to 500,001 to 1,000,000?

THanks,

Justin
 

Some videos you may like

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)

xenou

MrExcel MVP, Moderator
Joined
Mar 2, 2007
Messages
16,630
Office Version
2013
Platform
Windows
Not tested (i rarely use top in Access) but should work like this

select top (500000) * from Table where SomeID < 500000 order by SomeID
select top (500000) * from Table where SomeID >= 500000 and SomeID < 1000000 order by SomeID
select top (500000) * from Table where SomeID >= 1000000 and SomeID < 15000000 order by SomeID

If the IDs are not really sequential then you can't be sure of getting exactly 500,000 per chunk.
If you need to get exactly 500,000 per chunk then you have to store the ID's of what is exported so you can start the next batch from the same place.

Probably not ideal. Best to test your algorithm on a small table with say 10 chunks of 10, with only 100 records (more or less).

Another possibility - export the relevant IDs into a temporary-ish table, partition them into the right number of groups, and use that table to control the exports. This would provide a better audit and probably a better way of ensuring reliability (which can also be helped by recording what is exporting and validating the counts).
 

Watch MrExcel Video

Forum statistics

Threads
1,096,459
Messages
5,450,577
Members
405,619
Latest member
mjh237

This Week's Hot Topics

Top