dskanes said:
Hi Chris,
Thanks I changed the alias on my tables which solved my original problem and
Yes it makes SQL more readable.
However I noticed a couple of things that are now happening that I can’t seem
To resolve and I am a bit confused:
1. I get prompted to enter parameter value for the following fields:
Actualdailyhours, dailyhours, statutory. These fields are not calculated
values
In my query they are fields values from a table and the show is selected in
the query.
Also the query parameter box is empty.
2. My calculations no longer work for Excephrs, Reghrs, or Othrs. When I run
the SQL they all show up as 0.
3. I noticed some detail records are being skipped and not reported on my
report. For a given date there can be multiple records for same driver for
the same day with same route and routes cat.
I will insert my SQL not sure if its needed :
Any help is appreciated as I have been days trying to resolve my issues with
this
report.
Thanks
dskanes,
The Query, realigned for readability:
SELECT DSYD.DriverID
,[FirstName] & " " & [LastName] AS Name
,DSYD.SchWorkDate
,DSYD.[Route#]
,DSYD.RouteCategory
,DSYD.NumOfBreaks AS TotalBreak
,DSYD.DailyHours
,DSYD.ActualDailyHours
,DSYD.Statutory
,IIf([DriverSchedule_YTD]![ActualDailyHours]>0
,[DriverSchedule_YTD]![ActualDailyHours]-[DriverSchedule_YTD]![DailyHo
urs]) AS ExceptHrs
,Switch([DriverSchedule_YTD]![Statutory]="Y",0
,[DriverSchedule_YTD]![ActualDailyHours]>0,[DriverSchedule_YTD]![Actua
lDailyHours]
,[DriverSchedule_YTD]![DailyHours]>0,[DriverSchedule_YTD]![DailyHours]
,True,0) AS Reghrs
,Switch([DriverSchedule_YTD]![Statutory]="N",0
,[DriverSchedule_YTD]![ActualDailyHours]>0,[DriverSchedule_YTD]![Actua
lDailyHours]
,[DriverSchedule_YTD]![DailyHours]>0,[DriverSchedule_YTD]![DailyHours]
,True,0) AS Othrs
FROM DriversDescription AS DD1
INNER JOIN
DriverSchedule_YTD AS DSYD
ON DD1.DriverID = DSYD.DriverID
GROUP BY DSYD.DriverID
,[FirstName] & " " & [LastName]
,DSYD.SchWorkDate
,DSYD.[Route#]
,DSYD.RouteCategory
,DSYD.NumOfBreaks
,DSYD.DailyHours
,DSYD.ActualDailyHours
,DSYD.Statutory
,IIf([DriverSchedule_YTD]![ActualDailyHours]>0
,[DriverSchedule_YTD]![ActualDailyHours]-[DriverSchedule_YTD]![DailyHo
urs])
,Switch([DriverSchedule_YTD]![Statutory]="Y",0
,[DriverSchedule_YTD]![ActualDailyHours]>0,[DriverSchedule_YTD]![Actua
lDailyHours]
,[DriverSchedule_YTD]![DailyHours]>0,[DriverSchedule_YTD]![DailyHours]
,True,0)
,Switch([DriverSchedule_YTD]![Statutory]="N",0
,[DriverSchedule_YTD]![ActualDailyHours]>0,[DriverSchedule_YTD]![Actua
lDailyHours]
,[DriverSchedule_YTD]![DailyHours]>0,[DriverSchedule_YTD]![DailyHours]
,True,0)
HAVING (((DSYD.SchWorkDate) >= [forms]![Report Date
Range]![Beginning Order Date]
And (DSYD.SchWorkDate) <= [forms]![Report Date Range]![Ending
Order Date]))
ORDER BY DSYD.DriverID
,DSYD.SchWorkDate
,DSYD.[Route#]
,DSYD.RouteCategory;
First, I cannot figure out why you are doing a GROUP BY. There is no
Aggregation (SUM, COUNT, MAX, MIN). While access will let you do the
following (run on one of my example tables), which is the equivalent
of what is being done above:
SELECT I1.ItemID
,I1.Description
,I1.VendorItemID
FROM ItemMaster AS I1
GROUP BY I1.ItemID
,I1.Description
,I1.VendorItemID
It's the same as:
SELECT *
FROM ItemMaster AS I1
So . . . there is no purpose to the GROUP BY above. I delete it,
along with the HAVING, turning that part into a WHERE clause.
SELECT DSYD.DriverID
,[FirstName] & " " & [LastName] AS Name
,DSYD.SchWorkDate
,DSYD.[Route#]
,DSYD.RouteCategory
,DSYD.NumOfBreaks AS TotalBreak
,DSYD.DailyHours
,DSYD.ActualDailyHours
,DSYD.Statutory
,IIf([DriverSchedule_YTD]![ActualDailyHours]>0
,[DriverSchedule_YTD]![ActualDailyHours]-[DriverSchedule_YTD]![DailyHo
urs]) AS ExceptHrs
,Switch([DriverSchedule_YTD]![Statutory]="Y",0
,[DriverSchedule_YTD]![ActualDailyHours]>0,[DriverSchedule_YTD]![Actua
lDailyHours]
,[DriverSchedule_YTD]![DailyHours]>0,[DriverSchedule_YTD]![DailyHours]
,True,0) AS Reghrs
,Switch([DriverSchedule_YTD]![Statutory]="N",0
,[DriverSchedule_YTD]![ActualDailyHours]>0,[DriverSchedule_YTD]![Actua
lDailyHours]
,[DriverSchedule_YTD]![DailyHours]>0,[DriverSchedule_YTD]![DailyHours]
,True,0) AS Othrs
FROM DriversDescription AS DD1
INNER JOIN
DriverSchedule_YTD AS DSYD
ON DD1.DriverID = DSYD.DriverID
WHERE (((DSYD.SchWorkDate) >= [forms]![Report Date
Range]![Beginning Order Date]
AND (DSYD.SchWorkDate) <= [forms]![Report Date Range]![Ending
Order Date]))
ORDER BY DSYD.DriverID
,DSYD.SchWorkDate
,DSYD.[Route#]
,DSYD.RouteCategory;
But wait, there are still a few adjustments to make, as Access didn't
quite change all the table names into the their aliases for you.
SELECT DSYD.DriverID
,DD1.FirstName & " " & DD1.LastName AS Name
,DSYD.SchWorkDate
,DSYD.[Route#]
,DSYD.RouteCategory
,DSYD.NumOfBreaks AS TotalBreak
,DSYD.DailyHours
,DSYD.ActualDailyHours
,DSYD.Statutory
,IIf(DSYD.ActualDailyHours > 0
,DSYD.ActualDailyHours - DSYD.DailyHours) AS ExceptHrs
,Switch(DSYD.Statutory="Y",0
,DSYD.ActualDailyHours>0,DSYD.ActualDailyHours
,DSYD.DailyHours>0,DSYD.DailyHours
,True,0) AS Reghrs
,Switch(DSYD.Statutory="N",0
,DSYD.ActualDailyHours>0,DSYD.ActualDailyHours
,DSYD.DailyHours>0,DSYD.DailyHours
,True,0) AS Othrs
FROM DriversDescription AS DD1
INNER JOIN
DriverSchedule_YTD AS DSYD
ON DD1.DriverID = DSYD.DriverID
WHERE (((DSYD.SchWorkDate) >= [forms]![Report Date
Range]![Beginning Order Date]
AND (DSYD.SchWorkDate) <= [forms]![Report Date Range]![Ending
Order Date]))
ORDER BY DSYD.DriverID
,DSYD.SchWorkDate
,DSYD.[Route#]
,DSYD.RouteCategory;
There, that cleans up the last of the Table aliases.
As to why all the calculations turn up 0, that depends on what data
you're running through the Query.
Select a small set of rows, and run your query on them to make sure
the Query still produces zeroes for those columns. Then present the
sample data here, including the dates currently being entered on the
form.
Sincerely,
Chris O.