LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 459
Default How do I limit the rows returned into Excel from a query

My original reply was going to be, "Which 30 rows?" but I decided to
be more helpful.

I'm not too familiar with MS Query so I had a play. Here's what my
query looked like in the SQL window:

SELECT MyKeyCol, MyDataCol
FROM LongTime

I then went to Edit, Options, Limit the number of records returned 30.
I'm immediately suspicious that it didn't ask me which 30 rows I
wanted. I then looked at the SQL window again: no change, it's showing
the same as before. Just as I thought, the query is returning all rows
from the datasource but only showing me an arbitrary 30. No wonder
when I send the results to Shee1 I have many more than 30 rows
populated.

Now to answer your question. To limit the number of records returned
by the datasource you have to change the SQL. For example, to show the
rows with the 30 highest values for MyKeyCol:

SELECT DISTINCT T1.MyDataCol
FROM LongTime T1
WHERE 30 (
SELECT COUNT(*)
FROM LongTime T2
WHERE T1.MyKeyCol < T2.MyKeyCol)

Note if your datasource is MS (MS Access, Excel, Jet, SQL Server), you
may find the proprietary TOP N syntax to your liking (I prefer ANSI
standard syntax for portability).

--

"jpb" wrote in message ...
I am trying to return data into excel from a query. The
query was written in MsQuery and selects from an access
database. I need to limit the results of the query to
only return 30 rows into my excel spreadsheet. I can set
the limit records option in MsQuery so that it only
returns 30 rows while in MsQuery, but when I refresh the
data in excel it still retrieves all of the rows.

Any help would be appreciated.
Thanks.

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to I set a limit on the value returned by a cell WavMaster Excel Worksheet Functions 3 February 3rd 09 06:54 PM
Limit returned value Patrick C. Simonds Excel Worksheet Functions 5 September 27th 08 02:29 PM
Limit returned value to last digit Patrick C. Simonds Excel Worksheet Functions 3 September 27th 08 05:02 AM
limit characters returned a cell reference Lila Excel Worksheet Functions 8 September 6th 06 03:33 AM
This query returned no data Tjeerd Excel Worksheet Functions 0 September 22nd 05 10:00 PM


All times are GMT +1. The time now is 01:47 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"