Hi John
Yes the SQL as posted does work and gives the correct counts but that is because the query only returns one row in it's current form (so it is not having a problem with the expression 0-20)
You have added another column to the query for 0-40 which again works fine when the query returns just one row (and that is indeed what I will do once I know the counting is working correctly for the 0-20 column)
But this isn't my problem - it is when I develop the query so that it returns more than one row - for example by removing the [enter match code] - in that case the query returns a row for each match code but the count in the 0-20 column is the same in every row.
The amended SQL for this is
SELECT Matches.Div, Matches.[match code], Count(Matches.id) AS [tot games], DCount("id","matches","[totbooks]<21 and [div]='" & [enter league code] & "' and [date] between #" & Format([date1],"mm/dd/yyyy") & "# and #" & Format([date2],"mm/dd/yyyy") & "# ") AS [0-20]
FROM Matches
WHERE (((Matches.Date) Between [date1] And [date2]))
GROUP BY Matches.Div, Matches.[match code]
HAVING (((Matches.Div)=[enter league code]))
ORDER BY Matches.Div;
FROM Matches
WHERE (((Matches.Date) Between [date1] And [date2]))
GROUP BY Matches.Div, Matches.[match code]
HAVING (((Matches.Div)=[enter league code]))
ORDER BY Matches.Div;
I want it to give me the count of matches which have a value in totbooks of <21 for each different match code record
cheers
Phil
On Wednesday, 8 January 2014, 13:10, John Viescas <JohnV@msn.com> wrote:
Phil-
I think the problem is you're trying to use the filter values inside the DCount instead of the value found in the current row. Does the query work as currently coded? I'm thinking that it's not happy that the [0-20] expression isn't also in the GROUP BY clause. If it is working, then you could try:
SELECT Matches.Div, Matches.[match code], Count(Matches.id) AS [tot games],
DCount("id","matches","[totbooks]<21 and [div]='" & [Div] & "' and [match code]=" & [match code] &
" and [date] between #" & Format([date1],"mm/dd/yyyy") & "# and #" & Format([date2],"mm/dd/yyyy") & "# ") AS [0-20],
DCount("id","matches","[totbooks]<41 and [div]='" & [Div] & "' and [match code]=" & [match code] &
" and [date] between #" & Format([date1],"mm/dd/yyyy") & "# and #" & Format([date2],"mm/dd/yyyy") & "# ") AS [0-40]
FROM MatchesWHERE (((Matches.Date) Between [date1] And [date2]) AND (Matches.Div = [enter league code]) AND (Matches.[match code] = [enter match code]))
GROUP BY Matches.Div, Matches.[match code];
John Viescas, Author
Microsoft Access 2010 Inside Out
Microsoft Access 2007 Inside Out
Microsoft Access 2003 Inside Out
Building Microsoft Access Applications
SQL Queries for Mere Mortals
(Paris, France)
On Jan 8, 2014, at 1:47 PM, Phil Knowles <pdk444444@yahoo.co.uk> wrote:
Hi JohnJust one table called matches - which is used to record football matches with associated data.the fields that are relevant to what I am trying to do areid - autonumber keydate - in UK date formatdiv - an alphanumeric code for the league or divison (or cup) that the match is part ofmatch code - a numeric ratingtotbooks - a numeric value based on the number of bookings in the game - between 0 and say a max of 150I want to be able to produce grids of information - an example of which is as followsdiv match code month tot games 0-20 0-40 0-60 30-50 40-60where I can enter a div (or select all divs)I can enter a match code (or select all match codes) andI can select the matches between 2 entered datesI want to be able to count the number of matches that have a value in totbooks that falls into the ranges specified ( as you can see the ranges are not mutually exclusive) - the ranges I have given are just examples and I may vary them.The query I have developed worked for just 1 div and 1 match code (before I tried to break it down into months) and the SQL isSELECT Matches.Div, Matches.[match code], Count(Matches.id) AS [tot games], DCount("id","matches","[totbooks]<21 and [div]='" & [enter league code] & "' and [match code]=" & [enter match code] & " and [date] between #" & Format([date1],"mm/dd/yyyy") & "# and #" & Format([date2],"mm/dd/yyyy") & "# ") AS [0-20]
FROM Matches
WHERE (((Matches.Date) Between [date1] And [date2]))
GROUP BY Matches.Div, Matches.[match code]
HAVING (((Matches.Div)=[enter league code]) AND ((Matches.[match code])=[enter match code]))
ORDER BY Matches.Div;Given what I want to do - not sure where to go from here.cheersPhil
On Wednesday, 8 January 2014, 12:15, John Viescas <JohnV@msn.com> wrote:
Phil-Having a tough time picturing this. What is the SQL of your entire query?What is the structure of your tables, and what are you trying to get out of them?John Viescas, AuthorMicrosoft Access 2010 Inside OutMicrosoft Access 2007 Inside OutMicrosoft Access 2003 Inside OutBuilding Microsoft Access ApplicationsSQL Queries for Mere Mortals(Paris, France)
On Jan 8, 2014, at 1:00 PM, Phil Knowles <pdk444444@yahoo.co.uk> wrote:Hi JohnI guess 'a spot of bother' is very English !!!Thank you - that sorted out my 'between dates' problem - but, as is always the case, I have now run into another problem.I am trying to do this in query design (rather than any VBA) by the way.The query itself is limiting the records it finds based on criteria entered and the field I am using the dcount function in is counting the number of records that not only satisfy all the query criteria but also 1 further test (the [totbooks]<21 element).This works fine as long as the query returns just one record - because of grouping.However I need the query to return several records and i need the dcount field to display the correct count for each subgrouping.Is this possible to do using this approach and if so what do I put in the dcount criteria to achieve it?orshould I be doing it in a different way - probably in VBA I imagine!at the moment it asks for div, and 2 dates and then finds all the records for div between the 2 dates and I have a field that gives the count of all the records it has found and my dcount field then gives a count of all those records with totbooks <21.I now need to subgroup the single record that the query returns by month (regardless of year) ie one record for all matches records with a January date and another record for Feb etc. - and for each of the query rows, a correct count of those records and a count of those records with totbooks <21Once I have worked out how to do this I need to add several more columns of a similar nature but with different ranges for totbooksHope I have explained it adequately - if not please ask for clarificatiioncheersPhil
On Wednesday, 8 January 2014, 11:10, John Viescas <JohnV@msn.com> wrote:
Phil-"Spot of bother" implies to me that you're not on a US machine. Date in predicates in SQL (which DCount uses) must be in US format if they're Short date. If the values in [Enter Date1] and [Enter Date2] are in European format (dd/mm/yyyy), you could get wrong results. For example 1/8/2013 (August 1, 2013 outside of the US) is interpreted by the query engine as January 8!Try this:DCount("id","matches","[totbooks]<21 and [div]='" & [enter league code] & "' and [date] between #" & Format([enter date1], "mm/dd/yyyy") & "# and #" & Format([enter date2], "mm/dd/yyyy") & "# ")John Viescas, AuthorMicrosoft Access 2010 Inside OutMicrosoft Access 2007 Inside OutMicrosoft Access 2003 Inside OutBuilding Microsoft Access ApplicationsSQL Queries for Mere Mortals(Paris, France)
On Jan 8, 2014, at 11:47 AM, <pdk444444@yahoo.co.uk> <pdk444444@yahoo.co.uk> wrote:Hi Guys,I am having a spot of bother again - help please.I am trying to do a count of a set of records for a field in a query.I am user parameters and all was going well until I tried to change a date bit to between 2 dates - I am now getting odd results.I have tried the followingDCount("id","matches","[totbooks]<21 and [div]='" & [enter league code] & "' and [date] between #" & [enter date1] & "# and #" & [enter date2] & "# ")this returns a count that is much too highand alsoDCount("id","matches","[totbooks]<21 and [div]='" & [enter league code] & "' and [date] >= #" & [enter date1] & "# and [date]<= #" & [enter date2] & "# ")this returns 0I must admit it took me a while to work out all the delimiters needed to accomodate parameters and I wonder if they are not correct?cheersPhil
__._,_.___
| Reply via web post | Reply to sender | Reply to group | Start a New Topic | Messages in this topic (7) |
.
__,_._,___
Tidak ada komentar:
Posting Komentar