Selasa, 08 November 2016

Re: [MS_AccessPros] Query not responding

 

Hi John
 
I am now trying your suggestion to split out my dcounts into individual queries.
 
I have done the first one but am struggling with the syntax for the 2nd inner join in the main query.
 
I presume once I get that correct the pattern will be similar for all the subsequent inner joins.
 
So if you could help me out with how to do the second inner join please that would be good.
 
cheers
 
Phil
 
 



From: "John Viescas JohnV@msn.com [MS_Access_Professionals]" <MS_Access_Professionals@yahoogroups.com>
To: "MS_Access_Professionals@yahoogroups.com" <MS_Access_Professionals@yahoogroups.com>
Sent: Monday, 7 November 2016, 16:22
Subject: Re: [MS_AccessPros] Query not responding

 
Duane-

That may be an even better idea!  Didn't to occur to me to use a Tally Table, but I should have considering we devote an entire chapter to them in my new book.

John Viescas, Author
Effective SQL
SQL Queries for Mere Mortals 
Microsoft Access 2010 Inside Out
Microsoft Access 2007 Inside Out
Microsoft Access 2003 Inside Out
Building Microsoft Access Applications 
(Paris, France)




On Nov 7, 2016, at 5:17 PM, Duane Hookom duanehookom@hotmail.com [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com> wrote:



I would create a table of ranges like:

RangeName  FromNum   ToNum
0                      0                    0
0-10                0                  10
0-20                0                  20
0-30                0                  30
etc

Then create a crosstab query with both tables and no joins. Set the criteria under TotBooks to:
BETWEEN FromNum and ToNum

Use RangeName as the Column Headings and 
Season, Avg(totbooks), Count(ID), Sum(Abs(SendingsOff>0)) as Row Headings.
Count(ID) can be your value.

You can do the percentages in the report or form with control sources like:

=[0-10]/[totg]

WHEN your ranges change, maintain your table rather than editing a query.

Duane Hookom




From: MS_Access_Professionals@yahoogroups.com <MS_Access_Professionals@yahoogroups.com> on behalf of John Viescas JohnV@msn.com[MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com>
Sent: Monday, November 7, 2016 9:53 AM
To: MS_Access_Professionals@yahoogroups.com
Subject: Re: [MS_AccessPros] Query not responding
 


Phil-

I would pull out each of the DCounts into separate queries.  For example, convert:

DCount("id","matches for grid - league","[totbooks]=0 and [refid]= [forms]![live games]![referee] and [season] = '" & [season] & "' and month([date])<>5 ")/[totg]

into:

qryZero:
SELECT MGL.Season, COUNT(id) As Count0
FROM [matches for grid - league] AS MGL
WHERE [totbooks]=0 AND [refid]= [forms]![live games]![referee] and month([date])<>5
GROUP BY Season;

Then incorporate it back into your main query using an INNER JOIN:

SELECT [Matches for grid - league].Season, Count([Matches for grid - league].id) AS totg, Avg([Matches for grid - league].totbooks) AS avbk, SUM(qryZero.Count0) / totg As 0
FROM [Matches for grid - league] INNER JOIN qryZero ON [Matches for grid - league].Season = qryZero.Season
WHERE (((Month([date]))<>5) AND (([Matches for grid - league].Refid)=[forms]![Live Games]![referee]))
GROUP BY [Matches for grid - league].Season
ORDER BY [Matches for grid - league].Season DESC;

I threw the SUM in there to make sure you don't get a bogus error because Count0 isn't in the GROUP BY - it should be a SUM of exactly one row!  "Simply" do that for each of your DCOUNTs - building up a complex INNER JOIN.

John Viescas, Author
Effective SQL
SQL Queries for Mere Mortals 
Microsoft Access 2010 Inside Out
Microsoft Access 2007 Inside Out
Microsoft Access 2003 Inside Out
Building Microsoft Access Applications 
http://www.viescas.com/
Welcome to the home of John Viescas Consulting. If you're at all interested in Microsoft Access or SQL Server, this is the place to be! Check out the book ...

 
(Paris, France)




On Nov 7, 2016, at 4:29 PM, Phil Knowles pdk444444@yahoo.co.uk [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com> wrote:



Here goes - good luck!
 
SELECT [Matches for grid - league].Season, Count([Matches for grid - league].id) AS totg, Avg([Matches for grid - league].totbooks) AS avbk, DCount("id","matches for grid - league","[totbooks]=0 and [refid]= [forms]![live games]![referee] and [season] = '" & [season] & "' and month([date])<>5 ")/[totg] AS 0, DCount("id","matches for grid - league","[totbooks]<11 and [refid]= [forms]![live games]![referee] and [season] = '" & [season] & "' and month([date])<>5 ")/[totg] AS [0-10], DCount("id","matches for grid - league","[totbooks]<21 and [refid]= [forms]![live games]![referee] and [season] = '" & [season] & "' and month([date])<>5 ")/[totg] AS [0-20], DCount("id","matches for grid - league","[totbooks]<31 and [refid]= [forms]![live games]![referee] and [season] = '" & [season] & "' and month([date])<>5 ")/[totg] AS [0-30], DCount("id","matches for grid - league","[totbooks]<41 and [refid]= [forms]![live games]![referee] and [season] = '" & [season] & "' and month([date])<>5 ")/[totg] AS [0-40], DCount("id","matches for grid - league","[totbooks]<51 and [refid]= [forms]![live games]![referee] and [season] = '" & [season] & "' and month([date])<>5 ")/[totg] AS [0-50], DCount("id","matches for grid - league","[totbooks]<61 and [refid]= [forms]![live games]![referee] and [season] = '" & [season] & "' and month([date])<>5 ")/[totg] AS [0-60], DCount("id","matches for grid - league","[totbooks]<66 and [refid]= [forms]![live games]![referee] and [season] = '" & [season] & "' and month([date])<>5 ")/[totg] AS [0-65], DCount("id","matches for grid - league","[totbooks]<71 and [refid]= [forms]![live games]![referee] and [season] = '" & [season] & "' and month([date])<>5 ")/[totg] AS [0-70], DCount("id","matches for grid - league","[totbooks] between 30 and 40 and [refid]= [forms]![live games]![referee] and [season] = '" & [season] & "' and month([date])<>5 ")/[totg] AS [30-40], DCount("id","matches for grid - league","[totbooks] between 40 and 60 and [refid]= [forms]![live games]![referee] and [season] = '" & [season] & "' and month([date])<>5 ")/[totg] AS [40-60], DCount("id","matches for grid - league","[sendingsoff]>0 and [refid]= [forms]![live games]![referee] and [season] = '" & [season] & "' and month([date])<>5 ")/[totg] AS [reds%]
FROM [Matches for grid - league]
WHERE (((Month([date]))<>5) AND (([Matches for grid - league].Refid)=[forms]![Live Games]![referee]))
GROUP BY [Matches for grid - league].Season
ORDER BY [Matches for grid - league].Season DESC;
before my last change I had it working on the table 'matches' but I need it to analyse a particular type of match (ie league matches) so I changed it to run on a query which selects just the league matches.
 
there are about 60000 matches and maybe 45000 league matches.
 
cheers
 
Phil


On Monday, 7 November 2016, 15:21, "John Viescas JohnV@msn.com [MS_Access_Professionals]" <MS_Access_Professionals@yahoogroups.com> wrote:


Phil-

If a query is "too big", you should get a "query too complex" error.  If it's taking a long time to run, perhaps it could be optimized.  What's the SQL of the query?

John Viescas, Author
Effective SQL
SQL Queries for Mere Mortals 
Microsoft Access 2010 Inside Out
Microsoft Access 2007 Inside Out
Microsoft Access 2003 Inside Out
Building Microsoft Access Applications 
(Paris, France)




On Nov 7, 2016, at 4:14 PM, Phil Knowles pdk444444@yahoo.co.uk [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com> wrote:



Hi John
 
That looks as if it might be where the issue lies - I will look into it and let you know 
 
many thanks for that.
 
Another one for you whilst I have you if you don't mind.
 
I have a query which causes the message 'Access is not responding' - it is quite a complex query in that it has about 12 fields which use fairly involved dcounts.
 
Is it possible that a query simply becomes too 'big' to run? 
 
cheers
 
Phil















__._,_.___

Posted by: Phil Knowles <pdk444444@yahoo.co.uk>
Reply via web post Reply to sender Reply to group Start a New Topic Messages in this topic (18)

Have you tried the highest rated email app?
With 4.5 stars in iTunes, the Yahoo Mail app is the highest rated email app on the market. What are you waiting for? Now you can access all your inboxes (Gmail, Outlook, AOL and more) in one place. Never delete an email again with 1000GB of free cloud storage.


.

__,_._,___

Tidak ada komentar:

Posting Komentar