Results 1 to 2 of 2
  1. #1
    Nobody is offline Novice
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    8

    Query Optimization Inquiry

    I have a query which takes ages to run, and I have three questions:

    1) Do the "key" symbols (found in Access 2007 at least) show which fields have been indexed? Or is this something completely different?



    2) The only field I want results from (with a key) is FIELD1. With numbers stored as text (I'm not IT, I wonder why). All of these numbers are in the format "YYYYMM" (yearmonth). In my query, I have a where statement on FIELD1, as follows:
    Code:
    WHERE (FIELD1 Between [FIELD1 yyyymm?] and ([FIELD1 yyyymm?]-200))
    grabbing the last two years of data, from the "yyyymm" inputted from the user (parameter query). Does this work with indexing? (especially considering these values are stored as text!)

    3) Is there a superior way?

    Thanks!

  2. #2
    Nobody is offline Novice
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    8
    UPDATE:
    1) Are my primary keys, which I understand are the initial index.

    2) If I use the above SQL:
    Code:
    WHERE (FIELD1 Between [FIELD1 yyyymm?] and ([FIELD1 yyyymm?]-200))
    then it takes approx 35min to run. If I simplify the code to a single string to MATCH against:
    Code:
    WHERE (FIELD1 ="201006")
    it comes back in seconds.

    So what appears to be occurring is the BETWEEN function requires a numeric range and so I assume the query has to first convert each record in FIELD1 to a number (essentiall CLng()) and then perform the logic to see if it is in the range. This is a problem because using CLng() takes forever (my experience with this function via the ODBC connection to the table) and/or it doesn't utilize the indexing!

    To test this hypothesis I ran a query with this:
    Code:
    (RUNYYMM In ("201006","201005","201004","201003","201002","201001","200912","200911","200910","200909","200908","200907","200906","200905","200904","200903","200902","200901","200812","200811","200810","200809","200808","200807","200806"))
    and this came back in 11min. However, this disables the usefulness of my parameter query... not essential, but I would like to maintain this function.

    3) So is there a way to utilize user input, of a single date (YYYYMM), to generate the last two years worth of data through a single query? (Utilizing the index on the text field)

    The only way I can think of to take a single date and modify it to my needs is with VBA, and while I can do that, I'd like to know if a query-only solution is possible.

Please reply to this thread with any new information or opinions.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums