K
Kay
Hi
I need to display the total count of records added to 3 different
tables and display the results by day(how many were added each day). I
have created 2 queries as shown below. The second query (q22) looks at
the first (q2) to get its results. The problem is when searching
between say a period of last 3 days (from 19th to 21st) it displays the
following results:
XDate Jobs
0 18
19/03/2006 4
20/03/2006 8
21/03/2006 6
The 18 jobs next to xdate(0) are meant to be part of the 3 days (19th
to 21st). I think(not sure) that it is only looking up the count from
the one table and the remaining 18 are from the other 2 tables.
Any help is very much appreciated!
First query (q2)
SELECT MAX([Date]) AS XDate,
COUNT(*) AS Current, 0 AS Bookings, 0 AS Contracts
FROM [Current Jobs]
WHERE [Date] BETWEEN [Start Date (dd/mm/yyyy) ] AND [End Date
(dd/mm/yyyy) ]
GROUP BY [Date]
UNION ALL
SELECT MAX([Date]) AS XDate,
0 AS Current, COUNT(*) AS Bookings, 0 AS Contracts
FROM Bookings
WHERE [Date] BETWEEN [Start Date (dd/mm/yyyy) ] AND [End Date
(dd/mm/yyyy) ]
GROUP BY [Date]
UNION ALL SELECT MAX([Date]) AS XDate,
0 AS Current, 0 AS Bookings, COUNT(*) AS Contracts
FROM [Contract Jobs]
WHERE [Date] BETWEEN [Start Date (dd/mm/yyyy) ] AND [End Date
(dd/mm/yyyy) ]
GROUP BY [Date];
Second query (q22)
SELECT MIN([Q2].[XDate]) AS Dates,
Sum([Q2].[Current]+[Q2].[Bookings]+[Q2].[Contracts]) AS Jobs
FROM Q2
GROUP BY [Q2].[XDate]
ORDER BY [Q2].[XDate]
I need to display the total count of records added to 3 different
tables and display the results by day(how many were added each day). I
have created 2 queries as shown below. The second query (q22) looks at
the first (q2) to get its results. The problem is when searching
between say a period of last 3 days (from 19th to 21st) it displays the
following results:
XDate Jobs
0 18
19/03/2006 4
20/03/2006 8
21/03/2006 6
The 18 jobs next to xdate(0) are meant to be part of the 3 days (19th
to 21st). I think(not sure) that it is only looking up the count from
the one table and the remaining 18 are from the other 2 tables.
Any help is very much appreciated!
First query (q2)
SELECT MAX([Date]) AS XDate,
COUNT(*) AS Current, 0 AS Bookings, 0 AS Contracts
FROM [Current Jobs]
WHERE [Date] BETWEEN [Start Date (dd/mm/yyyy) ] AND [End Date
(dd/mm/yyyy) ]
GROUP BY [Date]
UNION ALL
SELECT MAX([Date]) AS XDate,
0 AS Current, COUNT(*) AS Bookings, 0 AS Contracts
FROM Bookings
WHERE [Date] BETWEEN [Start Date (dd/mm/yyyy) ] AND [End Date
(dd/mm/yyyy) ]
GROUP BY [Date]
UNION ALL SELECT MAX([Date]) AS XDate,
0 AS Current, 0 AS Bookings, COUNT(*) AS Contracts
FROM [Contract Jobs]
WHERE [Date] BETWEEN [Start Date (dd/mm/yyyy) ] AND [End Date
(dd/mm/yyyy) ]
GROUP BY [Date];
Second query (q22)
SELECT MIN([Q2].[XDate]) AS Dates,
Sum([Q2].[Current]+[Q2].[Bookings]+[Q2].[Contracts]) AS Jobs
FROM Q2
GROUP BY [Q2].[XDate]
ORDER BY [Q2].[XDate]