I have a form that I need the user to be able to choose what ever they want to fill in to manipulate the query. Currently I can only get a few combinations to work. All combinations require the date range and the employee id range. Currently I can only get the combination of the jobNo to work alone. If I combine it with the cost code or dept I get all the job no's instead of the single job I type in. Data would look like this
emloyee ID.....CostCode.....JobNO......Dept......date...
20470..........FC10.........I-7301.....Field.....9/8/2012
30142..........FC30.........E-7617......SUB......9/8/2012
30125..........BC10.........E-5475......Truck....9/7/2012
14253..........BC10.........I-7317......Truck....9/8/2012
25862..........FC30.........I-7301......SUB......9/7/2012
The code I have been trying to get to work is below.
Thank you for any assistance with this.
Micki
emloyee ID.....CostCode.....JobNO......Dept......date...
20470..........FC10.........I-7301.....Field.....9/8/2012
30142..........FC30.........E-7617......SUB......9/8/2012
30125..........BC10.........E-5475......Truck....9/7/2012
14253..........BC10.........I-7317......Truck....9/8/2012
25862..........FC30.........I-7301......SUB......9/7/2012
The code I have been trying to get to work is below.
Code:
INSERT INTO PayrollHisTable ( EmployeeId, EarningCode, CostCode, JobNo, cPayRate_amt, Hours, LastName, FirstName, Middle, Dept, [Date] )
SELECT dbo_EmpPayDetailHist.szEmployeeId_tr AS EmployeeId, dbo_EmpPayDetailHist.szEarnCode_tr AS EarningCode, dbo_JobCostCode.szSearch_key AS CostCode, dbo_JobSearch.szSearch_key AS JobNo, dbo_EmpPayDetailHist.cPayRate_amt, Sum(dbo_EmpPayDetailHist.dHoursWorked_qty) AS SumOfdHoursWorked_qty, dbo_tblPaEmpGenInfo.LastName, dbo_tblPaEmpGenInfo.FirstName, dbo_tblPaEmpGenInfo.MiddleInit, dbo_EmpPayDetailHist.szDepartmentId_tr, dbo_EmpPayDetailHist.dtWork_dt
FROM ((dbo_EmpPayDetailHist INNER JOIN dbo_JobCostCode ON dbo_EmpPayDetailHist.lJobCostCode_id = dbo_JobCostCode.lJobCostCode_id) INNER JOIN dbo_JobSearch ON dbo_EmpPayDetailHist.lJob_id = dbo_JobSearch.lJobSearch_id) LEFT JOIN dbo_tblPaEmpGenInfo ON dbo_EmpPayDetailHist.szEmployeeId_tr = dbo_tblPaEmpGenInfo.EmployeeId
GROUP BY dbo_EmpPayDetailHist.szEmployeeId_tr, dbo_EmpPayDetailHist.szEarnCode_tr, dbo_JobCostCode.szSearch_key, dbo_JobSearch.szSearch_key, dbo_EmpPayDetailHist.cPayRate_amt, dbo_tblPaEmpGenInfo.LastName, dbo_tblPaEmpGenInfo.FirstName, dbo_tblPaEmpGenInfo.MiddleInit, dbo_EmpPayDetailHist.szDepartmentId_tr, dbo_EmpPayDetailHist.dtWork_dt
HAVING (((dbo_EmpPayDetailHist.szEmployeeId_tr) Between [Forms]![frmPayrollHistory]![txtEmployeeFrom] And [Forms]![frmPayrollHistory]![txtEmployeeTo:]) AND ((dbo_JobSearch.szSearch_key) Between [Forms]![frmPayrollHistory]![txtJobNoFrom] And [Forms]![frmPayrollHistory]![txtJobNoTo]) AND ((dbo_EmpPayDetailHist.dtWork_dt) Between [Forms]![frmPayrollHistory]![txtStart] And [Forms]![frmPayrollHistory]![txtEnd])) OR (((dbo_EmpPayDetailHist.szEmployeeId_tr) Between [Forms]![frmPayrollHistory]![txtEmployeeFrom] And [Forms]![frmPayrollHistory]![txtEmployeeTo:]) AND ((dbo_JobCostCode.szSearch_key) Between [Forms]![frmPayrollHistory]![txtCostCode] And [Forms]![frmPayrollHistory]![txtCostCodeto]) AND ((dbo_JobSearch.szSearch_key) Between [Forms]![frmPayrollHistory]![txtJobNoFrom] And [Forms]![frmPayrollHistory]![txtJobNoTo]) AND ((dbo_EmpPayDetailHist.dtWork_dt) Between [Forms]![frmPayrollHistory]![txtStart] And [Forms]![frmPayrollHistory]![txtEnd])) OR (((dbo_EmpPayDetailHist.szEmployeeId_tr) Between [Forms]![frmPayrollHistory]![txtEmployeeFrom] And [Forms]![frmPayrollHistory]![txtEmployeeTo:]) AND ((dbo_JobSearch.szSearch_key) Between [Forms]![frmPayrollHistory]![txtJobNoFrom] And [Forms]![frmPayrollHistory]![txtJobNoTo]) AND ((dbo_EmpPayDetailHist.szDepartmentId_tr) Between [Forms]![frmPayrollHistory]![txtdeptfrom] And [Forms]![frmPayrollHistory]![txtdeptto]) AND ((dbo_EmpPayDetailHist.dtWork_dt) Between [Forms]![frmPayrollHistory]![txtStart] And [Forms]![frmPayrollHistory]![txtEnd])) OR (((dbo_EmpPayDetailHist.szEmployeeId_tr) Between [Forms]![frmPayrollHistory]![txtEmployeeFrom] And [Forms]![frmPayrollHistory]![txtEmployeeTo:]) AND ((dbo_JobCostCode.szSearch_key) Between [Forms]![frmPayrollHistory]![txtCostCode] And [Forms]![frmPayrollHistory]![txtCostCodeto]) AND ((dbo_EmpPayDetailHist.dtWork_dt) Between [Forms]![frmPayrollHistory]![txtStart] And [Forms]![frmPayrollHistory]![txtEnd])) OR (((dbo_EmpPayDetailHist.szEmployeeId_tr) Between [Forms]![frmPayrollHistory]![txtEmployeeFrom] And [Forms]![frmPayrollHistory]![txtEmployeeTo:]) AND ((dbo_JobCostCode.szSearch_key) Between [Forms]![frmPayrollHistory]![txtCostCode] And [Forms]![frmPayrollHistory]![txtCostCodeto]) AND ((dbo_EmpPayDetailHist.szDepartmentId_tr) Between [Forms]![frmPayrollHistory]![txtdeptfrom] And [Forms]![frmPayrollHistory]![txtdeptto]) AND ((dbo_EmpPayDetailHist.dtWork_dt) Between [Forms]![frmPayrollHistory]![txtStart] And [Forms]![frmPayrollHistory]![txtEnd])) OR (((dbo_EmpPayDetailHist.szEmployeeId_tr) Between [Forms]![frmPayrollHistory]![txtEmployeeFrom] And [Forms]![frmPayrollHistory]![txtEmployeeTo:]) AND ((dbo_EmpPayDetailHist.szDepartmentId_tr) Between [Forms]![frmPayrollHistory]![txtdeptfrom] And [Forms]![frmPayrollHistory]![txtdeptto]) AND ((dbo_EmpPayDetailHist.dtWork_dt) Between [Forms]![frmPayrollHistory]![txtStart] And [Forms]![frmPayrollHistory]![txtEnd])) OR (((dbo_EmpPayDetailHist.szEmployeeId_tr) Between [Forms]![frmPayrollHistory]![txtEmployeeFrom] And [Forms]![frmPayrollHistory]![txtEmployeeTo:]) AND ((dbo_JobCostCode.szSearch_key) Between [Forms]![frmPayrollHistory]![txtCostCode] And [Forms]![frmPayrollHistory]![txtCostCodeto]) AND ((dbo_JobSearch.szSearch_key) Between [Forms]![frmPayrollHistory]![txtJobNoFrom] And [Forms]![frmPayrollHistory]![txtJobNoTo]) AND ((dbo_EmpPayDetailHist.szDepartmentId_tr) Between [Forms]![frmPayrollHistory]![txtdeptfrom] And [Forms]![frmPayrollHistory]![txtdeptto]) AND ((dbo_EmpPayDetailHist.dtWork_dt) Between [Forms]![frmPayrollHistory]![txtStart] And [Forms]![frmPayrollHistory]![txtEnd]));
Thank you for any assistance with this.
Micki