How do I use TOP in my query?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

My query starts out like this:

SELECT Dlookup(Table) AS SITE, ...

My TOP value is also stored in the same table as the SITE Dlookup. How do I
use the TOP protocol in the query?

SELECT TOP Dlookup(Table) AS ?, Dlookup(Table) AS SITE, ...

Thanks!
 
Dear Kou:

I presume that your "TOP value" is the number of rows desired.

You cannot obtain this from within the query. You could write VBA code that
retrieves the value and generates the SQL text string for the query prior to
its exectuion. That would be the way I know to do this.

Tom Ellison
 
If that is the case, then should I leave TOP X in the original SQL query
string, then use a Table QueryDef, and replace the "X" with the stored value
in the table, and run the execution? Are you following me?
 
Dear Kou Vang:

You would have to do something to make this changes at the last moment,
whether it reads TOP X in the saved query or something else. Since TOP X
would be an error, perhaps TOP 1 would surffice. Since you must alter this
before running it, I'm not sure what advantage there is to saving the query
at all. You could just have the SQL in the code that generates the version
to be run and save the effort to code it's retrieval from the stored query.

Tom Ellison
 
Back
Top