The table structure described is just for guidance. The column names are different compared to that of the DB.
I have a rather an unusual DB. I have agent table (Agents) with following structure.
A_ID(PK)| AgentName | Team
------------------------------------
1 | Abi | New
2 | Carl | New
3 | James | New
I have two other tables that has several fields but the ones in question have fields like..
Table: Transactions
ID(PK) | manyColumns | Agent_ID | OUTCOME
--------------------------------------------------------
96 | ... | 1 | 9
98 | .... | 2 | 8
99 | ..... | 3 | 1
Table: RAWDATA
ID(PK) | manyColumns | Agent_ID | BANK_OUTCOME
-------------------------------------------------------------
1234 | ... | 1 | 3
1114 | .... | 2 | 333
1745 | ..... | 3 | 123
I have a log table with the details of the staff working hours..
Table: AGENT_ATTENDANCE
ATT_ID | Hours Worked | Agent_ID_FK
-------------------------------------------
96 | 7.5 | 1
98 | 7.5 | 2
99 | 7.5 | 3
I also have a details of staff pay, hours contracted.
Table: AGENT_DETAILS
DT_ID | Hours WK | Pay | Agent_ID_FK
-------------------------------------------------------
96 | 37.5 | 15600 | 1
98 | 37.5 | 15600 | 2
99 | 37.5 | 15600 | 3
I have created separate queries but I want to display as one.. As the calculation depend on each other.. I am not sure how to do it.. The following are separate Queries.. How can I JOIN them as one??
Query – 1:
PARAMETERS [EnterStartDate:] DateTime, [EnterEndDate:] DateTime;
SELECT Agents.[Agent Name],
Sum(IIf((([TRANSACTIONS].[BankOutcome]=3) Or ([TRANSACTIONS].[BankOutcome]=333)),1,0)) AS PositiveOutcome,
Count(RAWDATA.Outcome) AS TotalRecordsUsed
FROM (RAWDATA LEFT JOIN Agents ON RAWDATA.[AGENT_ID] = Agents.A_ID) LEFT JOIN
TRANSACTIONS ON RAWDATA.ID = TRANSACTIONS.RAW_ID
WHERE (((RAWDATA.DialedDate) Between [EnterStartDate:] And [EnterEndDate:]))
GROUP BY Agents.[Agent Name], RAWDATA.AGENT_ID
HAVING (((RAWDATA.AGENT_ID) Is Not Null));
Query – 2:
PARAMETERS [EnterStartDate:] DateTime, [EnterEndDate:] DateTime;
SELECT Agents.[Agent Name], AGENT_DETAILS.WK_TARGET_HOURS,
Sum(AGENT_ATTENDENCE.HoursWorked_Day) AS [Actual Hours Worked],
[WK_TARGET_HOURS]-[Actual Hours Worked] AS [Hours Lost], AGENT_DETAILS.SALARY,
Round([SALARY]/252/([WK_TARGET_HOURS]/5),2) AS [Hourly Rate], [Hourly Rate]*[Actual Hours Worked] AS [Staff Cost]
FROM (Agents INNER JOIN AGENT_DETAILS ON Agents.A_ID = AGENT_DETAILS.AGENT_ID_fk)
INNER JOIN AGENT_ATTENDENCE ON Agents.A_ID = AGENT_ATTENDENCE.AGENT_ID_fk
WHERE (((AGENT_ATTENDENCE.WorK_Date) Between [EnterStartDate:] And [EnterEndDate:]))
GROUP BY Agents.[Agent Name], AGENT_DETAILS.WK_TARGET_HOURS, AGENT_DETAILS.SALARY,
Agents.Active, Agents.Team
HAVING (((Agents.Active)=True) AND ((Agents.Team)<>"Manager" And (Agents.Team)<>"Cust. Ser."));
Could attach the file if I could but I do not know how to.
I did not get into your code, but roughly you have 3 choices: