Results 1 to 8 of 8
  1. #1
    andy49's Avatar
    andy49 is offline VIP
    Windows 10 Access 2010 64bit
    Join Date
    Nov 2016
    Location
    London
    Posts
    1,051

    This query seems to run very slowly

    I'm using this query (qrybreakdownresultsfinal)



    Code:
    SELECT qryBreakDownResults.gradewhole1, qryBreakDownResults.Countgrade1, DSum("[Countgrade1]","qrybreakdownresults","[Gradewhole1]>=" & [Gradewhole1]) AS RT, Format([RT]/(select sum(CountGrade1) from qryBreakDownResults),"Percent") AS Pcen
    FROM qryBreakDownResults;
    The data comes from this query (qryBreakdownresults) which completes in a very short space of time
    Click image for larger version. 

Name:	Capture.PNG 
Views:	14 
Size:	5.5 KB 
ID:	31080

    I'm looking to get these results

    Click image for larger version. 

Name:	Capture1.PNG 
Views:	14 
Size:	9.5 KB 
ID:	31081

    But this takes a couple of seconds to complete and I wondered if I could speed it up

    If not, could I delay the display of the continuous form it comes from until the data has all been calculated.

  2. #2
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,933
    using domain functions in queries is the slowest way to do it - and running off another query may introduce performance issues.

    You can try to get to your final result by combining the two queries into one

    or try using a subquery e.g.

    (SELECT Sum([Countgrade1]) FROM qrybreakdownresults Q WHERE [Gradewhole1]>= qryBreakDownResults.[Gradewhole1]) AS RT

  3. #3
    andy49's Avatar
    andy49 is offline VIP
    Windows 10 Access 2010 64bit
    Join Date
    Nov 2016
    Location
    London
    Posts
    1,051
    Nearly!!! Got this.

    Click image for larger version. 

Name:	Capture.PNG 
Views:	12 
Size:	6.4 KB 
ID:	31091
    And sooooo much quicker but this is above my SQL. Can anyone see what needs changing?

  4. #4
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,933
    you probably haven't copied my example exactly - you need to alias the table in the subquery so it is not confused with the one in the main query

    qrybreakdownresults Q WHERE

  5. #5
    andy49's Avatar
    andy49 is offline VIP
    Windows 10 Access 2010 64bit
    Join Date
    Nov 2016
    Location
    London
    Posts
    1,051
    Thanks Ajax

    Am currently using this:

    SELECT qryBreakDownResults.gradewhole1, qryBreakDownResults.Countgrade1, (SELECT Sum([Countgrade1]) FROM qrybreakdownresults Q WHERE [Gradewhole1]>= qryBreakDownResults.[Gradewhole1]) AS rt
    FROM qryBreakDownResults;
    But error returns qryBreakdownresults.[gradewhole1] isn't a field or an expression?

    Any idea

  6. #6
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,933
    I just took your table and field names from your DSum function

  7. #7
    andy49's Avatar
    andy49 is offline VIP
    Windows 10 Access 2010 64bit
    Join Date
    Nov 2016
    Location
    London
    Posts
    1,051
    Thanks for all the help Ajax

    Found this which did the job perfectly.

    Code:
    SELECT a1.gradewhole, a1.CountOfgradewhole, Sum(a2.countofgradewhole) AS Running_Total, Format([Running_Total]/(select sum(Countofgradewhole) from qryBreakDownResults),"Percent") AS Pcent
    FROM qryBreakDownResults AS a1, qryBreakDownResults AS a2
    WHERE (((a1.gradewhole)<=[a2].[gradewhole])) OR (((a1.gradewhole)=[a2].[gradewhole]) AND ((a1.CountOfgradewhole)=[a2].[CountOfgradewhole]))
    GROUP BY a1.gradewhole, a1.CountOfgradewhole
    ORDER BY a1.gradewhole, a1.CountOfgradewhole DESC;

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    I tested Ajax's suggestion and it works perfectly. Here is the SQL:

    SELECT qryBreakDownResults.gradewhole1, qryBreakDownResults.Countgrade1, (SELECT Sum([Countgrade1]) FROM qrybreakdownresults Q WHERE [Gradewhole1]>= qryBreakDownResults.[gradewhole1]) AS RT, Format([RT]/(select sum(Countgrade1) from qryBreakDownResults),"Percent") AS Pcen
    FROM qryBreakDownResults;
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. after migrating to sql server some forms running slowly
    By masoud_sedighy in forum SQL Server
    Replies: 1
    Last Post: 10-06-2017, 04:06 AM
  2. Access 2013 Working Slowly
    By kik in forum Access
    Replies: 2
    Last Post: 03-20-2015, 12:04 PM
  3. Help I have a Form that is opening too slowly
    By RayMilhon in forum Forms
    Replies: 2
    Last Post: 12-05-2012, 12:51 PM
  4. Table loads too slowly
    By pcbrush in forum Access
    Replies: 8
    Last Post: 11-24-2010, 06:35 PM
  5. Tables open slowly
    By srferson in forum Access
    Replies: 1
    Last Post: 02-22-2010, 04:43 PM

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