The first section of code below is giving me fault totals and a total of Distinct Work Units.
The second section of code below is giving me the same fault totals by shift but the Work Units totals are all totals and not Distinct Work Units like the first bit of code. Could someone tell me where I am going wrong? This is code that I have received help on from earlier posts.
The second section of code below is giving me the same fault totals by shift but the Work Units totals are all totals and not Distinct Work Units like the first bit of code. Could someone tell me where I am going wrong? This is code that I have received help on from earlier posts.
Code:
Select SystemGroup, Count(*) As [Mechanical Totals]
From WorkUnitsFaultsMainTBL
WHERE (((WorkUnitsFaultsMainTBL.FaultCategory)<>"No Faults") AND (WorkUnitsFaultsMainTBL.FaultCategory)<>"Cosmetic") And ([TodaysDate] Between [Forms]![WorkUnitsFaultsMainFRM]![StartDateTxt] And [Forms]![WorkUnitsFaultsMainFRM]![EndDateTxt]And WorkUnitsFaultsMainTBL.BuildID In ("E010","C809","F001","C810","F187","A910","M173","M174"))
Group By SystemGroup
UNION ALL Select 'Total Work Units', count([WorkUnit]) from (select distinct [WorkUnit]
From WorkUnitsFaultsMainTBL
WHERE (((WorkUnitsFaultsMainTBL.FaultCategory)<>"No Faults") AND (WorkUnitsFaultsMainTBL.FaultCategory)<>"Cosmetic") And ([TodaysDate] Between [Forms]![WorkUnitsFaultsMainFRM]![StartDateTxt] And [Forms]![WorkUnitsFaultsMainFRM]![EndDateTxt])And WorkUnitsFaultsMainTBL.BuildID In ("E010","C809","F001","C810","F187","A910","M173","M174"));
Code:
Select SystemGroup,
sum(IIf(FirstShift = Yes, 1, 0)) as [First Shift],
sum(IIf(SecondShift = Yes, 1, 0)) as [Second Shift],
Count(*) As [Totals]
From WorkUnitsFaultsMainTBL
WHERE (((WorkUnitsFaultsMainTBL.FaultCategory)<>"No Faults") AND (WorkUnitsFaultsMainTBL.FaultCategory)<>"Cosmetic") And ([TodaysDate] Between [Forms]![WorkUnitsFaultsMainFRM]![StartDateTxt] And [Forms]![WorkUnitsFaultsMainFRM]![EndDateTxt] And WorkUnitsFaultsMainTBL.BuildID In ("E010","C809","F001","C810","F187","A910","M173","M174"))
Group By SystemGroup
UNION ALL Select 'Total Work Units',
sum(IIf(FirstShift = Yes, 1, 0)) as [First Shift],
sum(IIf(SecondShift = Yes, 1, 0)) as [Second Shift],
Count(*) As [Totals]
From
(select distinct [WorkUnit], [FirstShift], [SecondShift] from WorkUnitsFaultsMainTBL
Where [TodaysDate] Between [Forms]![WorkUnitsFaultsMainFRM]![StartDateTxt] And [Forms]![WorkUnitsFaultsMainFRM]![EndDateTxt]And WorkUnitsFaultsMainTBL.BuildID In ("E010","C809","F001","C810","F187","A910","M173","M174"));