I Would Like my Count Field Query to Return Zeroes for Dates With No Data Instead of Simply Not Listing That Date

I seem to have a continuous problem with this. I have a table with ALL possible dates (They are actually all Week Ending Saturday Dates.)

I have another table with actual data and the Week Ending Saturday Date associated with that piece of data.

My query is a joining query that uses ALL of the possible dates. However it does not seem to be doing that. There are weeks missing. I have my SQL below
SELECT Count(NZ(B_ClosedByWeek_CARs_Tbl.CAR_Num_Full,0)) AS Closed, CAR_Possible_WEDATES_W_Leaps_tbl.PossibleWeekEndingDates AS Week INTO C3_ClosedbyWeek_KOJ_Time_Line_Count_tbl
FROM B_ClosedByWeek_CARs_Tbl RIGHT JOIN CAR_Possible_WEDATES_W_Leaps_tbl ON B_ClosedByWeek_CARs_Tbl.WEDate = CAR_Possible_WEDATES_W_Leaps_tbl.PossibleWeekEndingDates
WHERE (((B_ClosedByWeek_CARs_Tbl.Problem_Location)="KOJ Cherry St" Or (B_ClosedByWeek_CARs_Tbl.Problem_Location)="KOJ Panel Plant" Or (B_ClosedByWeek_CARs_Tbl.Problem_Location)="KOJ Wood Plant") AND ((B_ClosedByWeek_CARs_Tbl.WEDate)<Now() And (B_ClosedByWeek_CARs_Tbl.WEDate)>#5/31/2010#))
GROUP BY CAR_Possible_WEDATES_W_Leaps_tbl.PossibleWeekEndingDates
ORDER BY CAR_Possible_WEDATES_W_Leaps_tbl.PossibleWeekEndingDates;

Open in new window

Rex85Asked:
Who is Participating?
 
mbizupConnect With a Mentor Commented:
It's taking me a bit to get my brain wrapped around your last comment, trying to visualize what you are describing.  It's one of the more challenging questions I've seen posted here in a while :)

If I'm understanding correcly, the 'missing' records you want have nothing in the Plant field and nothing in the date field, beause there is no data from your main table corresponding to the right-joined data in your "all dates" table.

You might be able to resolve this by revising your plant criteria to allow NULL plants, or maybe a combination of Null Dates and Null plants

Like this:

WHERE ((B_ClosedByWeek_CARs_Tbl.Problem_Location="KOJ Cherry St" Or B_ClosedByWeek_CARs_Tbl.Problem_Location="KOJ Panel Plant" Or B_ClosedByWeek_CARs_Tbl.Problem_Location="KOJ Wood Plant" OR B_ClosedByWeek_CARs_Tbl.Problem_Location IS NULL) etc...


Or This:

WHERE ((B_ClosedByWeek_CARs_Tbl.Problem_Location="KOJ Cherry St" Or B_ClosedByWeek_CARs_Tbl.Problem_Location="KOJ Panel Plant" Or B_ClosedByWeek_CARs_Tbl.Problem_Location="KOJ Wood Plant" OR (B_ClosedByWeek_CARs_Tbl.Problem_Location IS NULL AND B_ClosedByWeek_CARs_Tbl.WEDate IS NULL)) etc...


0
 
mbizupCommented:
Try changing your criteria to include NULL values for WEDate.

With your right join, these will be NULL for dates that are not present.

I think this will do it  for your WHERE clause:

WHERE (((B_ClosedByWeek_CARs_Tbl.Problem_Location)="KOJ Cherry St" Or (B_ClosedByWeek_CARs_Tbl.Problem_Location)="KOJ Panel Plant" Or (B_ClosedByWeek_CARs_Tbl.Problem_Location)="KOJ Wood Plant") AND (((B_ClosedByWeek_CARs_Tbl.WEDate)<Now() And (B_ClosedByWeek_CARs_Tbl.WEDate)>#5/31/2010#) OR B_ClosedByWeek_CARs_Tbl.WEDate IS NULL))

Open in new window

0
 
Rex85Author Commented:
No. That didn't workl. It's Still skipping some weeks. I thought a Join with a list of possible dates would return nulls for those weeks for which no data existed...not just skip them.
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
mbizupCommented:
It should... I believe it is your criteria that is preventing that from happening.

Can you post a sample?
0
 
Rex85Author Commented:
Sorry. I should have included this. This is the query output. It is clearly skipping 8/14/2010.
Skipped-Date-1.jpg
0
 
mbizupCommented:
Understood - If you are able to post an actual sample DB, it might be easier to work with.
0
 
Rex85Author Commented:
These are the two tables. Sorry if cross posted.
data-Table-1.jpg
Possible-Date-Table-1.jpg
0
 
Rex85Author Commented:
I can't really post the db. These tables are made by make table queries that query Linked tables that are part of a very large db.
0
 
mbizupCommented:
Sorry - I think I'm not being clear... I understand the problem you are having with the missing weeks.

Are you able to post an actual sample database (not just screenshots)?  
0
 
mbizupCommented:
Ah- okay...

I'll try to work with this as-is later on if no one else picks it up.
0
 
mbizupCommented:
For now, run this test...

Take out the date criteria altogether (I realize this will not yield the correct results).


Do the missing weeks show up with the date criteria gone?
0
 
Rex85Author Commented:
Yes. You are correct. It is the WHERE clause. I'm not sure how, or if, I can get there from here. I may need to split the data table into a separate table for each location. As soon as I stipulate the location inclusion in the WHERE, it skips the blanks because they aren't associated with the blank dates....because they're blank.
blank-dates-no-criteria.jpg
0
 
mbizupCommented:
Give this a try...

Instead of using the WEDate from the table that has missing weeks, use the PossiblWeekEndingDate from the table with all of the dates as your criteria.  Like this:

((CAR_Possible_WEDATES_W_Leaps_tbl.PossibleWeekEndingDates)<Now() And (CAR_Possible_WEDATES_W_Leaps_tbl.PossibleWeekEndingDates)>#5/31/2010#))
0
 
lluddenCommented:
Try this:

SELECT      Count(NZ(B_ClosedByWeek_CARs_Tbl.CAR_Num_Full,0)) AS Closed,
            CAR_Possible_WEDATES_W_Leaps_tbl.PossibleWeekEndingDates AS Week
INTO C3_ClosedbyWeek_KOJ_Time_Line_Count_tbl
FROM CAR_Possible_WEDATES_W_Leaps_tbl
      LEFT OUTER JOIN B_ClosedByWeek_CARs_Tbl ON B_ClosedByWeek_CARs_Tbl.WEDate = CAR_Possible_WEDATES_W_Leaps_tbl.PossibleWeekEndingDates
WHERE (B_ClosedByWeek_CARs_Tbl.Problem_Location="KOJ Cherry St"
      Or B_ClosedByWeek_CARs_Tbl.Problem_Location="KOJ Panel Plant"
      Or B_ClosedByWeek_CARs_Tbl.Problem_Location="KOJ Wood Plant")
      AND B_ClosedByWeek_CARs_Tbl.WEDate BETWEEN #5/31/2010# AND Now()
GROUP BY CAR_Possible_WEDATES_W_Leaps_tbl.PossibleWeekEndingDates
ORDER BY CAR_Possible_WEDATES_W_Leaps_tbl.PossibleWeekEndingDates

0
 
Rex85Author Commented:
lludden:

Thank you, but that still skips the weeks that are nulls. (See Below)

I tried a double join, joining the data with both the possible dates and the possible locations, but Access couldn't handle it. It gave me the "ambiguous join" message that I needed to use a subquery. I have yet to successfully put one of those together.
Skipped-Dates-2.jpg
0
 
mbizupCommented:
Did you try modifying the where clause to the SQL in my last post?
0
 
mbizupCommented:
Just that part of the where clause,  nothing else.
0
 
Rex85Author Commented:
mbizup:

Thank you. Yes. I did. It did not make a difference. When I removed the plant location, it showed the problem.

The data is in the form of  Plant  Date CAR_Number

When I join that data with the Possible Dates, but don't restrict the Plant, I get the nulls. That is what I want. However, since it only returns one null for a given possible date, and that is not associated with a plant location, by restricting location in the WHERE clause, I filter out the nulls.
0
 
Rex85Author Commented:
mbizup: I believe your assessment is correct. I can find dates with no data (nulls) by joining the dates with data table to the possible dates table, but that returns one null per date with no data. The problem is that there are four locations, so I need to do that for each locations, essentially asking a query to tell me what data is NOT there for four different locations at each of the possible dates.

If three plants had no data for a date, but one did, I would need the one plant's data for that date and three nulls for that date, one for each separate location that had no data. It's probably possible, but I am working right now on breaking it out....doing it with a query by plant, rather than one very clever query.

I will try what you have suggested though. I would much rather reduce my queries by 75%.
0
 
Rex85Author Commented:
Thank you for your help. I really appreciate it.

Rex
0
All Courses

From novice to tech pro — start learning today.