Multiple queries using one date range

I meant the SQL string. We can't see everything using this view. NoKnocks is using Count()

Press the totals button and that will add an additional line.
NoKnocks should use expression
Op Date should use group by
I can't tell aoubt the third field
 
SELECT Count([Operational AAR/Summary]![Investigation Type]) AS NoKnocks, [Operational AAR/Summary].[Op Date]
FROM [Operational AAR/Summary]
WHERE ((([Operational AAR/Summary].[Op Date]) Between [Forms]![Date Parameters]![Start Date] And [Forms]![Date Parameters]![End Date]) AND (([Operational AAR/Summary]![Investigation Type])=7));
 
The third field should be group by
 
SELECT Count([Operational AAR/Summary]![Investigation Type]) AS NoKnocks, [Operational AAR/Summary].[Op Date]
FROM [Operational AAR/Summary]
GROUP BY Count([Operational AAR/Summary]![Investigation Type]), [Operational AAR/Summary].[Op Date], [Operational AAR/Summary]![Investigation Type]
HAVING ((([Operational AAR/Summary].[Op Date]) Between [Forms]![Date Parameters]![Start Date] And [Forms]![Date Parameters]![End Date]) AND (([Operational AAR/Summary]![Investigation Type])=7));
??
 
Change the HAVING back to WHERE since it is referencing input fields rather than output fields.
 
SELECT Count([Operational AAR/Summary]![Investigation Type]) AS NoKnocks, [Operational AAR/Summary].[Op Date]
FROM [Operational AAR/Summary]
GROUP BY Count([Operational AAR/Summary]![Investigation Type]), [Operational AAR/Summary].[Op Date], [Operational AAR/Summary]![Investigation Type]
Where ((([Operational AAR/Summary].[Op Date]) Between [Forms]![Date Parameters]![Start Date] And [Forms]![Date Parameters]![End Date]) AND (([Operational AAR/Summary]![Investigation Type])=7));
1635273908696.png
 
The WHERE clause needs to go before the Group by clause.

I thought you were changing the properties on the QBE rather than editing the SQL itself.
 
GROUP BY Count([Operational AAR/Summary]![Investigation Type]), [Operational AAR/Summary].[Op Date], [Operational AAR/Summary]![Investigation Type]

just needs to be

GROUP BY [Operational AAR/Summary].[Op Date]

and if you want to group by [Operational AAR/Summary]![Investigation Type] then you need to include it in your select part as well
 
The WHERE clause needs to go before the Group by clause.

I thought you were changing the properties on the QBE rather than editing the SQL itself.
First off, what is QBE?
I switched the Where to go before the Group By and all I did was cut and paste but now I have another error message:
SELECT Count([Operational AAR/Summary]![Investigation Type]) AS NoKnocks, [Operational AAR/Summary].[Op Date]
FROM [Operational AAR/Summary]
Where ((([Operational AAR/Summary].[Op Date]) Between [Forms]![Date Parameters]![Start Date] And [Forms]![Date Parameters]![End Date]) AND (([Operational AAR/Summary]![Investigation Type])=7));
GROUP BY Count([Operational AAR/Summary]![Investigation Type]), [Operational AAR/Summary].[Op Date], [Operational AAR/Summary]![Investigation Type]
1635344941381.png


From this query I'm trying to only pick out a specific investigation type (7) as well as by date.
 
The QBE is design view as opposed to SQL view. Remove the semi-colon at the end of the WHERE clause and see if that helps.
 
Oh ok. Well, that worked with the query. When I went back to the Date Parameters form, I received the following error:
1635346572923.png
 
I received the following error when trying the form again after correcting the SQL
1635347390630.png

This popped up several times (obviously something with the queries), however this time when it brought up the report, several of the answers appeared however they were incorrect.

This is the SQL:

SELECT Count([Operational AAR/Summary]![Investigation Type]) AS NoKnocks, [Operational AAR/Summary].[Op Date]
FROM [Operational AAR/Summary]
WHERE ((([Operational AAR/Summary].[Op Date]) Between Forms![Date Parameters]![Start Date] And Forms![Date Parameters]![End Date]) And (([Operational AAR/Summary]![Investigation Type])=7))
GROUP BY [Operational AAR/Summary].[Op Date];
 
If [Operational AAR/Summary] is a query, does it run without error? If not, and it doesn't have an Expr1 field, keep drilling down until you find the offending query. Or can you attach the db here?
 
[Operational AAR/Summary] is the main table. I was able to get everything running until I had to add the date parameter....
Upload file is too large. =(
 
Try doing a compact/repair and then zipping it. Or just attach a db with that table.
 
The query above runs fine. The error comes from the item 10 subform:

SELECT Count([Operational AAR/Summary]![Person(s)/Animal(s) Injured/Killed]) AS InjuredKilled, [Operational AAR/Summary]![Person(s)/Animal(s) Injured/Killed] AS Expr1, [Operational AAR/Summary].[Op Date]
FROM [Operational AAR/Summary]
WHERE ((([Operational AAR/Summary]![Person(s)/Animal(s) Injured/Killed])=2) And (([Operational AAR/Summary].[Op Date]) Between Forms![Date Parameters]![Start Date] And Forms![Date Parameters]![End Date]))
GROUP BY [Operational AAR/Summary].[Op Date];

The field in Expr1 needs to be in the Group By clause, or have an aggregate function applied to it.
 
Or deleted, since I just noticed it's the same as the first field.
 
I deleted it. Same error appears this time only once. Again the answers provided are wrong.
 
I assume you have the same thing happening in another subreport. I'm on the phone so can't check right now.
 

Users who are viewing this thread

Back
Top Bottom