Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Show every date in range with 0 if no info

Status
Not open for further replies.

netrusher

Technical User
Joined
Feb 13, 2005
Messages
952
Location
US
Below is the SQL I have for a query. This query finds
WU Totals, Leak Totals, and pct of leaks for me and works
fine. It is also based on a date range. What I would like
to know is, say if the date range is 6/1/08-6/30/08 and
there are some dates that do not have any information, is
there a way for me to make each date in the range show
and populate zero's if there is no info?

Code:
SELECT Format(TodaysDate,'yyyy-mm-dd') AS [Date], WU.[WU Totals], Count(*) AS [Leak Totals], (Count(*)/WU.[WU Totals]*1) AS [Percent]
FROM WorkUnitsFaultsMainTBL, [SELECT vTbl.Day as WUDay,
              Count(*) AS [WU Totals]
       FROM
             (SELECT DISTINCT Format(TodaysDate,'yyyy-mm-dd') AS [Day], WorkUnit
              FROM WorkUnitsFaultsMainTBL
              WHERE BuildID IN ('E010','C809','F001','C810','F187','A910','M173','M174')
               AND (TodaysDate BETWEEN [Forms]![Queries_ReportsFRM]![StartDateTxt] 
                                    And [Forms]![Queries_ReportsFRM]![EndDateTxt])) AS vTbl
       GROUP BY vTbl.Day ]. AS WU
WHERE (((WorkUnitsFaultsMainTBL.Problem) Like "*leak*") AND ((WorkUnitsFaultsMainTBL.TodaysDate) Between [Forms]![Queries_ReportsFRM]![StartDateTxt] And [Forms]![Queries_ReportsFRM]![EndDateTxt]) AND ((WorkUnitsFaultsMainTBL.BuildID) In ("E010","C809","F001","C810","F187","A910","M173","M174")) AND ((Format([TodaysDate],'yyyy-mm-dd'))=[WU].[WUDay]))
GROUP BY Format(TodaysDate,'yyyy-mm-dd'), WU.[WU Totals]
ORDER BY Format(TodaysDate,'yyyy-mm-dd'), WU.[WU Totals], Count(*) DESC;
 
what you need is a table with all dates


and left join this query to that table


Select Dayofyear,Dt.*
From Calander
left join ( you whole Above Query) dt
on Calander.Dayofyear=dt.Date
where Calander.Dayofyear between
[Forms]![Queries_ReportsFRM]![StartDateTxt]
And [Forms]![Queries_ReportsFRM]![EndDateTxt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top