J
Jaazaniah
I have a table setup tbl_Hours that tracks employees, times started
and finished, and the project number details of the work. The table,
when initially designed, went the quick and dirty way: Example of the
field list:
Emp
Activity#
....
Date
Start Time
End Time
I've been trying to reduce it down to a single date/time field to save
space and front-end programming time, but when I try to spit out the
results that the reporting queries are looking for (like number of
hours spent based on current time field and next greatest time field),
the subquery fails. Here's what I'm trying to use in the query
qry_TimeSpent:
(SELECT Min(t1.Date) AS ENDDATE FROM tbl_Hours AS t1 INNER JOIN
tbl_Hours AS t2 on t1.HistoryID = t2.HistoryID WHERE t1.Date >
t2.Date) AS To
I've tried a few variations, but am obviously doing something wrong as
this subquery returns null values.
Goal: Return next largest Date value for the current Emp
Here's the SQL, the Left joins are there to feed into the reporting
structure. it can change, but would prefer not to.
SELECT tbl_Hours.Emp, tbl_Hours.Date,
(SELECT Min(t1.Date) AS ENDDATE
FROM tbl_Hours AS t1 INNER JOIN tbl_Hours AS t2
ON t1.HistoryID = t2.HistoryID WHERE t1.Date > t2.Date)
AS [To], tbl_Hours.Activity
FROM (((tbl_Hours LEFT JOIN tbl_Activities ON tbl_Hours.Activity =
tbl_Activities.ActivityID) LEFT JOIN tbl_Projects ON
tbl_Activities.Project = tbl_Projects.ProjectID) LEFT JOIN tbl_Clients
ON tbl_Projects.Client = tbl_Clients.ClientID) LEFT JOIN tbl_Employees
ON tbl_Hours.Emp = tbl_Employees.EmpID;
and finished, and the project number details of the work. The table,
when initially designed, went the quick and dirty way: Example of the
field list:
Emp
Activity#
....
Date
Start Time
End Time
I've been trying to reduce it down to a single date/time field to save
space and front-end programming time, but when I try to spit out the
results that the reporting queries are looking for (like number of
hours spent based on current time field and next greatest time field),
the subquery fails. Here's what I'm trying to use in the query
qry_TimeSpent:
(SELECT Min(t1.Date) AS ENDDATE FROM tbl_Hours AS t1 INNER JOIN
tbl_Hours AS t2 on t1.HistoryID = t2.HistoryID WHERE t1.Date >
t2.Date) AS To
I've tried a few variations, but am obviously doing something wrong as
this subquery returns null values.
Goal: Return next largest Date value for the current Emp
Here's the SQL, the Left joins are there to feed into the reporting
structure. it can change, but would prefer not to.
SELECT tbl_Hours.Emp, tbl_Hours.Date,
(SELECT Min(t1.Date) AS ENDDATE
FROM tbl_Hours AS t1 INNER JOIN tbl_Hours AS t2
ON t1.HistoryID = t2.HistoryID WHERE t1.Date > t2.Date)
AS [To], tbl_Hours.Activity
FROM (((tbl_Hours LEFT JOIN tbl_Activities ON tbl_Hours.Activity =
tbl_Activities.ActivityID) LEFT JOIN tbl_Projects ON
tbl_Activities.Project = tbl_Projects.ProjectID) LEFT JOIN tbl_Clients
ON tbl_Projects.Client = tbl_Clients.ClientID) LEFT JOIN tbl_Employees
ON tbl_Hours.Emp = tbl_Employees.EmpID;