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!

Query to show total count

Status
Not open for further replies.

netrusher

Technical User
Joined
Feb 13, 2005
Messages
952
Location
US
Below is the SQL of my query. This query shows total counts
of WorkUnits and Leaks. My dilemma is:

It only shows total count of workunits on days that leaks
show up. I still would like the total count of workunits
based on the daterange even if there are no leaks. Please
advise.

Code:
SELECT "4-5T" AS Truck, WorkUnitsFaultsMainTBL.TodaysDate, 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 ('G004','E818','N005','F813','P005','G813')
               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 ("G004","E818","N005","F813","P005","G813")) AND ((Format([TodaysDate],'yyyy-mm-dd'))=[WU].[WUDay]))
GROUP BY WorkUnitsFaultsMainTBL.TodaysDate, WU.[WU Totals]
ORDER BY WorkUnitsFaultsMainTBL.TodaysDate, WU.[WU Totals], Count(*) DESC;
 
The below fix worked.


Code:
Count(IIF ( WorkUnitsFaultsMainTBL.Problem Like "*leak*", 1,null) )
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top