S
Scott
Below is part of a subquery that I'm coding in vba for a report. I left the
"10" hard coded for the example in CODE 1. The "10" represents the results
of a calculation that needs the e.empID column also shown. If I just replace
the 10 with e.empID, within the vbe, the e.empID is not recognized as being
part of the sql SELECT statement. I have no way to write a SELECT statement
to get the e.empID column. CODE 2 shows the complete SQL.
I know there is always a way to do things, but I can't see it. Any ideas?
CODE 1
*********************
(Select Sum(t_data.dataOT_Hrs)
FROM t_data
WHERE t_data.empID = e.empID) / 10 ) AS OT_Hrs_YTD_Avg
CODE 2
*********************
sSQL = "SELECT d.dataID, e.empLast, e.empFirst, dt.dtDateBegin,
dt.dtDateEnd, dt.dtWeek, " & _
"d.empID, d.jobID, j.jobName, d.deptID,
dp.deptName, s.shiftName, d.shiftID, d.dataOT_Base, " & _
"d.dataRegHrs, d.dataOT_Hrs, d.dataRegHrs_RT,
d.millID, " & _
"(SELECT Sum(da.dataOT_Hrs) FROM t_date dt INNER
JOIN t_data da ON dt.dtID = da.dtID " & _
"WHERE da.empID = e.empID AND ((dt.dtDateBegin
Forms!f_rpt_overtime.Form.txtDateBegin & "#)) AS OT_Hrs_YTD, " & _
"((Select Sum(t_data.dataOT_Hrs) FROM t_data " &
_
"WHERE t_data.empID = e.empID) / " &
GetEmpOT_Weeks([empID], Forms!f_rpt_overtime.Form.cboWeek.Column(1)) & " AS
OT_Hrs_YTD_Avg, " & _
"dt.dtID " & _
"FROM t_shifts AS s INNER JOIN (t_jobs AS j INNER JOIN
(t_dept AS dp INNER JOIN (t_date AS dt INNER JOIN " & _
"(t_data AS d INNER JOIN t_employee AS e ON
d.empID = e.empID) ON dt.dtID = d.dtID) ON dp.deptID = d.deptID) " &_
"ON j.jobID = d.jobID) ON s.shiftID = d.shiftID
" & _
"WHERE dt.dtID = " & Forms!f_rpt_overtime.Form.cboWeek &
" " & _
"ORDER BY e.empLast, e.empFirst, d.shiftID"
"10" hard coded for the example in CODE 1. The "10" represents the results
of a calculation that needs the e.empID column also shown. If I just replace
the 10 with e.empID, within the vbe, the e.empID is not recognized as being
part of the sql SELECT statement. I have no way to write a SELECT statement
to get the e.empID column. CODE 2 shows the complete SQL.
I know there is always a way to do things, but I can't see it. Any ideas?
CODE 1
*********************
(Select Sum(t_data.dataOT_Hrs)
FROM t_data
WHERE t_data.empID = e.empID) / 10 ) AS OT_Hrs_YTD_Avg
CODE 2
*********************
sSQL = "SELECT d.dataID, e.empLast, e.empFirst, dt.dtDateBegin,
dt.dtDateEnd, dt.dtWeek, " & _
"d.empID, d.jobID, j.jobName, d.deptID,
dp.deptName, s.shiftName, d.shiftID, d.dataOT_Base, " & _
"d.dataRegHrs, d.dataOT_Hrs, d.dataRegHrs_RT,
d.millID, " & _
"(SELECT Sum(da.dataOT_Hrs) FROM t_date dt INNER
JOIN t_data da ON dt.dtID = da.dtID " & _
"WHERE da.empID = e.empID AND ((dt.dtDateBegin
"dt.dtDateBegin <= #" &= #" & txtYearBegin & "#) And " & _
Forms!f_rpt_overtime.Form.txtDateBegin & "#)) AS OT_Hrs_YTD, " & _
"((Select Sum(t_data.dataOT_Hrs) FROM t_data " &
_
"WHERE t_data.empID = e.empID) / " &
GetEmpOT_Weeks([empID], Forms!f_rpt_overtime.Form.cboWeek.Column(1)) & " AS
OT_Hrs_YTD_Avg, " & _
"dt.dtID " & _
"FROM t_shifts AS s INNER JOIN (t_jobs AS j INNER JOIN
(t_dept AS dp INNER JOIN (t_date AS dt INNER JOIN " & _
"(t_data AS d INNER JOIN t_employee AS e ON
d.empID = e.empID) ON dt.dtID = d.dtID) ON dp.deptID = d.deptID) " &_
"ON j.jobID = d.jobID) ON s.shiftID = d.shiftID
" & _
"WHERE dt.dtID = " & Forms!f_rpt_overtime.Form.cboWeek &
" " & _
"ORDER BY e.empLast, e.empFirst, d.shiftID"