Results 1 to 4 of 4
  1. #1
    Star Lounger
    Join Date
    Jan 2001
    Location
    Littleton, Colorado, USA
    Posts
    73
    Thanks
    0
    Thanked 0 Times in 0 Posts

    AGONIZING Slow Queries (2K, SP3)

    I have combined the data from two separate OBDC databases to provide daily production values. To do so, I've pulled the relevant data from both databases, limited to the last 2 weeks. Each of these queries runs approximately 1 minute for daily data.

    I then add the daily production into total production by production area for the month, then divide by the number of days in the week(calculated within the query) if the week was last week, or the latest production date in the database if the week is the current week. This is for average daily production. This query takes 3 minutes to run.

    The problem is, because we are looking at production in four different ways, each with different calculations, I must do a union query for each production type. This makes the query run 12-15 minutes, depending on network speed.

    Here is the SQL code:

    <hr><font color=blue>SELECT [DLY_DTE]-Weekday([DLY_DTE],0)+1 AS WeekStart, qryProduction.ReportArea, Sum(qry2WkDailyTGProduction.TG) AS PROD, "PROD" AS Type, "DUMMY" AS AssetName, DateDiff("d",[DLY_DTE]-Weekday([DLY_DTE],0)+1,IIf([DLY_DTE]-Weekday([DLY_DTE],0)+1=Date()-Weekday(Date(),0)+1,[MaxDate],[DLY_DTE]-Weekday([DLY_DTE],0)+7))+1 AS NumDays, 0 AS TypeOrder
    FROM qryProduction_MaxVolumeDate, qry2WkDailyTGProduction INNER JOIN qryProduction_INFO ON qry2WkDailyTGProduction.CTRL_NBR = qryLine_INFO.CTRL_NBR
    GROUP BY [DLY_DTE]-Weekday([DLY_DTE],0)+1, qryCAO_WELL_INFO.ReportField, "PROD", "DUMMY", DateDiff("d",[DLY_DTE]-Weekday([DLY_DTE],0)+1,IIf([DLY_DTE]-Weekday([DLY_DTE],0)+1=Date()-Weekday(Date(),0)+1,[MaxDate],[DLY_DTE]-Weekday([DLY_DTE],0)+7))+1, 0;</font color=blue><hr>
    I suspect the main holdup is the DMAX I use to extract <font color=blue>[MaxDate]</font color=blue> in the database. At first, I included DMAX as part of the query, but then decided to make a query on its own (qryProduction_MaxVolumeDate), and reference it in the production query.

    Because not everyone has MS Access, I'm using MS Query to bring the data into MS Excel and performing the average daily production calculation there, using TG and NumDays. This is also why I can't use fancy macros to load recordsets into memory for [MaxDate] and avoid lengthy DMAXs.

    Any hints on speeding up this agonizingly slow process?

    Thanks in advance.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: AGONIZING Slow Queries (2K, SP3)

    In this situation it might be a good idea to create make-table queries and run them on a regular basis to create static tables. The Excel users can then use MS Query to get data from the tables.

  3. #3
    Star Lounger
    Join Date
    Jan 2001
    Location
    Littleton, Colorado, USA
    Posts
    73
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: AGONIZING Slow Queries (2K, SP3)

    I was afraid of that. Thanks, Hans.

  4. #4
    Gold Lounger
    Join Date
    Jun 2001
    Location
    Crystal Beach, FL, Florida, USA
    Posts
    3,436
    Thanks
    1
    Thanked 34 Times in 34 Posts

    Re: AGONIZING Slow Queries (2K, SP3)

    You'd probably be much better off by using a subquery to get that MAX value. Avoid DMAX (and Dcount, etc.) when doing queries.
    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •