I am querying the sum of delay time per job. The query successfully returns these sums, but does not return a value for a job if no delays occured. How do I make the query generate "0" for jobs which contained no delays.
with THIS...Code:SELECT DISTINCTROW DailyProduct.ProdID, Sum(DELAYTimePerDelayID.TotalDelayTime) AS [Sum Of TotalDelayTime] FROM (DailyProduct INNER JOIN DELAYTimePerDelayID ON DailyProduct.ProdID = DELAYTimePerDelayID.ProdID) INNER JOIN (DelayReasons INNER JOIN Delays ON DelayReasons.DelayReasonID = Delays.DelayReasonID) ON (DailyProduct.ProdID = Delays.ProdID) AND (DELAYTimePerDelayID.DelayID = Delays.DelayID) WHERE (((DelayReasons.DelayType)="Mechanical")) GROUP BY DailyProduct.ProdID HAVING (((Sum(DELAYTimePerDelayID.TotalDelayTime))=nz([column/Calculation],"0")));[/quote]
Hopefully, that one works for you. I was also under the impression that tried using DISTINCTROW to elimante duplicate records for the same job. If that was the purpose, you don't need it. The SUM function, coupled with GROUP BY does this for you.Code:SELECT DailyProduct.ProdID, IIF(Sum(DELAYTimePerDelayID.TotalDelayTime) > 0, Sum(DELAYTimePerDelayID.TotalDelayTime), 0) AS [Sum Of TotalDelayTime] FROM (DailyProduct INNER JOIN DELAYTimePerDelayID ON DailyProduct.ProdID = DELAYTimePerDelayID.ProdID) INNER JOIN (DelayReasons INNER JOIN Delays ON DelayReasons.DelayReasonID = Delays.DelayReasonID) ON (DailyProduct.ProdID = Delays.ProdID) AND (DELAYTimePerDelayID.DelayID = Delays.DelayID) WHERE (((DelayReasons.DelayType)="Mechanical")) GROUP BY DailyProduct.ProdID;
SELECT [ProdID]
FROM [DailyProduct]
WHERE [ProdID] NOT IN (SELECT [ProdID] FROM Delays);