Perhaps I'm missing someting....
The final product is exactly what I'm asking for but I'm not sure how you got there... Could you explain a little further? I modded the original statement to include my actual field and table names....
strSQL = "SELECT LastName, FirstName, Sum(CDbl([ControlledHours])) * 24 AS [Tot Ctr], Sum(CDbl([UncontrolledHours])) * 24 AS [Tot Unctr] FROM [CS-RepTable] INNER JOIN [DAT-DayStatsTable] ON [CS-RepTable].IDNUM = [DAT-DayStatsTable].IDNUM WHERE ((([DAT-DayStatsTable].DATE) Between" & "#" & tbsWeek.Tabs(1).Tag & "# AND #" & tbsWeek.Tabs(6).Tag & "#)) GROUP BY LastName, FirstName"
Isn't this selecting Lastname, Firstname ControlledHours and UncontrolledHours from the [CS-RepTable]??
The actual data resides in the [DAT-DayStatsTable]. But it's still coming out correctly even if I change the data in the [DAT-DayStatsTable]. Am I missing something here?
Not that I'm not greatful for the help or anything, I just want to know how it works naturally =)
Eiredrake
Re: Perhaps I'm missing someting....
Quote:
Originally posted by Eiredrake
The final product is exactly what I'm asking for but I'm not sure how you got there... Could you explain a little further? I modded the original statement to include my actual field and table names....
strSQL = "SELECT LastName, FirstName, Sum(CDbl([ControlledHours])) * 24 AS [Tot Ctr], Sum(CDbl([UncontrolledHours])) * 24 AS [Tot Unctr] FROM [CS-RepTable] INNER JOIN [DAT-DayStatsTable] ON [CS-RepTable].IDNUM = [DAT-DayStatsTable].IDNUM WHERE ((([DAT-DayStatsTable].DATE) Between" & "#" & tbsWeek.Tabs(1).Tag & "# AND #" & tbsWeek.Tabs(6).Tag & "#)) GROUP BY LastName, FirstName"
Isn't this selecting Lastname, Firstname ControlledHours and UncontrolledHours from the [CS-RepTable]??
The actual data resides in the [DAT-DayStatsTable]. But it's still coming out correctly even if I change the data in the [DAT-DayStatsTable]. Am I missing something here?
Not that I'm not greatful for the help or anything, I just want to know how it works naturally =)
Eiredrake
The key to the SQL statement is this part........
FROM [CS-RepTable] INNER JOIN [DAT-DayStatsTable] ON [CS-RepTable].IDNUM = [DAT-DayStatsTable].IDNUM
It is forming a join between the two tables on the unique key fields [IDNUM] which resides in both DAT-DayStatsTable & CS-RepTable
So, effectively you can reference the fields from either table as if it were one. This is a common method of joining One to Many relationship tables and you can build the statement to join many tables not just two.
The JOIN clause can also be used as LEFT JOIN or RIGHT JOIN if you need to retrieve all from one table not just the values where there is a match. LEFT being the first table referenced in the SQL statement. Unfortunately you will get an Invalid Use Of NULL Error if you try it on your example because CDbl([Contr]) would try to convert a null field.
The conversion of the hours fields was a bit of a fluke I came across one day, but it seems to work OK to give a fraction of a day.
Hope this is a little more useful.