SELECT
rm.CodeValue,
(select min(DateRec) from QueryCount2 where CodeValue=rm.CodeValue and DayCompleted is null) AS [Oldest Uncompleted],
nz(DateDiff("d",(select min(DateRec) from QueryCount2 where CodeValue=rm.CodeValue and DayCompleted is null),Now()-1),0) AS [Days Diff],
nz((select sum(CountApp) from QueryCount2 where CodeValue=rm.CodeValue and DateRec=format(now-1,"mm/dd/yyyy")),0 ) as [Incoming Today],
(select sum(a.Complete) as Total from (
SELECT DateRec, CodeValue, nz(DateCompl3, nz(DateCompl2, DateCompl1)) as DateCompl, iif(Day3=0, iif(Day2=0, Day1,Day2), Day3) as Complete
FROM QueryCount2) a where a.DateCompl = date() and a.CodeValue = rm.CodeValue) as [Completed]
FROM
QueryCount2 AS rm
GROUP BY rm.CodeValue;
|