Newbie SQL quetion

D

Duane

I would like to add a field from a third table and sum the field, but I am
having trouble with the syntax. I was wondering if someone could help me
with it?

The third table is called tblOvertime. It is joined to the Employee table
on the HRMN fields. I would like to SUM the Hours field in tblOvertime.

The first (my starting point) RecordSource works fine for my report.

Me.RecordSource = "SELECT Employee.HRMN, Employee.Group, " _
& "[LastName] & ', ' & [FirstName] & ' ' &
[MiddleInitial] AS EmpName, " _
& "Employee.Telephone, Employee.Shift, NES,
Employee.TotHours, Employee.TotHours, Employee.Group " _
& "FROM Employee " _
& "INNER JOIN Rot " _
& "ON Employee.Group = ROT.Group " _
& "WHERE ROT.[MOD" & intMod & "] = 1 AND
Employee.[" & Forms!frm_Switchboard!MyList & "] = -1 " _
& "AND Employee.[" &
Forms!frm_Switchboard!MyList & "H] > 0"

This is the one that is messed up.

Me.RecordSource = "SELECT Employee.HRMN, Employee.Group, " _
& "[LastName] & ', ' & [FirstName] & ' ' &
[MiddleInitial] AS EmpName, " _
& "Employee.Telephone, Employee.Shift,
Employee.NES, Rot.MOD6, " _
& "Sum(tblOvertime.Hours) AS SumOfHours, " _
& "FROM Rot INNER JOIN (Employee INNER JOIN
tblOvertime " _
& "ON Employee.HRMN = tblOvertime.HRMN) ON
Rot.Group = Employee.Group " _
& "GROUP BY Employee.HRMN, Employee.Group, "
_
& "[LastName] & ', ' & [FirstName] & ' ' &
[MiddleInitial], Employee.Telephone, " _
& "Employee.Shift, Employee.NES " _
& "WHERE ROT.[MOD" & intMod & "] = 1 "_
& " AND Employee.[" &
Forms!frm_Switchboard!MyList & "] = -1 " _
& "AND Employee.[" &
Forms!frm_Switchboard!MyList & "H] > 0"

Any help would be greatly appreciated.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Help with Sql statement 8
Help with report recordsource 2
sql help 1

Top