kentwoodjean
Technical User
Hoping someone can assist me. I am trying combine 3 separate queries into one (Union Query) and I am having difficulty. I have shown the SQL view of the 3 initial queries, along with the final query where I tried to join them. The final joining as the look I want, but does not give me accurate totals based on the way they are linked. As a final result I would like totals grouped together as follows:
Resp Main RespCat CountOfRecdDt CountofClosedDt Countof Pending(countofContract*) Avg Age
Receipts
SELECT tblLastUpdated.[Recd Dt], Count(tblLastUpdated.[Recd Dt]) AS [CountOfRecd Dt], tblLastUpdated.[Resp Cd]
FROM tblLastUpdated
GROUP BY tblLastUpdated.[Recd Dt], tblLastUpdated.[Resp Cd]
HAVING (((tblLastUpdated.[Recd Dt]) Like "*2004*"));
Closes
SELECT tblLastUpdated.[Closed Dt], Count(tblLastUpdated.[Closed Dt]) AS [CountOfClosed Dt], tblLastUpdated.[Resp Cd]
FROM tblLastUpdated
GROUP BY tblLastUpdated.[Closed Dt], tblLastUpdated.[Resp Cd]
HAVING (((tblLastUpdated.[Closed Dt]) Like "*2004*"));
Pending
SELECT Count(tblOpenCases.[Contract #]) AS [CountOfContract #], Avg((Date()-[Last St Date])) AS AvgAge, RespCdeLst.RespID, RespCdeLst.RespCat, RespCdeLst.RespMain
FROM tblOpenCases INNER JOIN RespCdeLst ON tblOpenCases.[Resp Cd] = RespCdeLst.RespCde
GROUP BY RespCdeLst.RespID, RespCdeLst.RespCat, RespCdeLst.RespMain;
Final Query grouping the Previous 3 queries
SELECT [Countof Closed DateRespCde].[CountOfClosed Dt], CountofRecdDate1.[CountOfRecd Dt], CountofRecdDate1.[Recd Dt], PendingCases.[CountOfContract #], PendingCases.AvgAge, PendingCases.[Resp Cd], PendingCases.RespID, PendingCases.RespDef, PendingCases.RespCat, PendingCases.RespMain
FROM (CountofRecdDate1 INNER JOIN PendingCases ON CountofRecdDate1.[Resp Cd] = PendingCases.[Resp Cd]) INNER JOIN [Countof Closed DateRespCde] ON PendingCases.[Resp Cd] = [Countof Closed DateRespCde].[Resp Cd]
WHERE (((CountofRecdDate1.[Recd Dt])=[Weekending Date (05/03/04)]) AND (([Countof Closed DateRespCde].[Closed Dt])=[Recd Dt]))
ORDER BY PendingCases.RespCat;
Resp Main RespCat CountOfRecdDt CountofClosedDt Countof Pending(countofContract*) Avg Age
Receipts
SELECT tblLastUpdated.[Recd Dt], Count(tblLastUpdated.[Recd Dt]) AS [CountOfRecd Dt], tblLastUpdated.[Resp Cd]
FROM tblLastUpdated
GROUP BY tblLastUpdated.[Recd Dt], tblLastUpdated.[Resp Cd]
HAVING (((tblLastUpdated.[Recd Dt]) Like "*2004*"));
Closes
SELECT tblLastUpdated.[Closed Dt], Count(tblLastUpdated.[Closed Dt]) AS [CountOfClosed Dt], tblLastUpdated.[Resp Cd]
FROM tblLastUpdated
GROUP BY tblLastUpdated.[Closed Dt], tblLastUpdated.[Resp Cd]
HAVING (((tblLastUpdated.[Closed Dt]) Like "*2004*"));
Pending
SELECT Count(tblOpenCases.[Contract #]) AS [CountOfContract #], Avg((Date()-[Last St Date])) AS AvgAge, RespCdeLst.RespID, RespCdeLst.RespCat, RespCdeLst.RespMain
FROM tblOpenCases INNER JOIN RespCdeLst ON tblOpenCases.[Resp Cd] = RespCdeLst.RespCde
GROUP BY RespCdeLst.RespID, RespCdeLst.RespCat, RespCdeLst.RespMain;
Final Query grouping the Previous 3 queries
SELECT [Countof Closed DateRespCde].[CountOfClosed Dt], CountofRecdDate1.[CountOfRecd Dt], CountofRecdDate1.[Recd Dt], PendingCases.[CountOfContract #], PendingCases.AvgAge, PendingCases.[Resp Cd], PendingCases.RespID, PendingCases.RespDef, PendingCases.RespCat, PendingCases.RespMain
FROM (CountofRecdDate1 INNER JOIN PendingCases ON CountofRecdDate1.[Resp Cd] = PendingCases.[Resp Cd]) INNER JOIN [Countof Closed DateRespCde] ON PendingCases.[Resp Cd] = [Countof Closed DateRespCde].[Resp Cd]
WHERE (((CountofRecdDate1.[Recd Dt])=[Weekending Date (05/03/04)]) AND (([Countof Closed DateRespCde].[Closed Dt])=[Recd Dt]))
ORDER BY PendingCases.RespCat;