Limit record count in query

D

David

Hello all,
I have a query that will return over 65K records (rows). My end goal is to
export this to Excel via code. Excel has a limit of 65K rows on a single
tab. So, 65K to tab1, the rest of the records to tab2. I figured I would
have query1 that would limit the results to 65K, and query2 that would start
at 65K +1 to the end.

How can I limit query1 to 65K and query2 to start at 65K +1?
 
D

Duane Hookom

I'm not sure how efficient this will be but you could try:

SELECT TOP 65000 *
FROM [query that will return over 65K records]
ORDER BY PrimaryKeyField;

and
SELECT *
FROM [query that will return over 65K records]
WHERE PrimaryKeyField Not IN (SELECT TOP 65000 PrimaryKeyField
FROM [query that will return over 65K records]
ORDER BY PrimaryKeyField);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top