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],
(SELECT Format((Sum(a.Complete)/60),"0.00" ) AS Total
FROM (SELECT CodeValue,
nz(DateCompl3, nz(DateCompl2, DateCompl1)) as DateCompl, iif(Time3=0, iif(Time2=0, Time1,Time2), Time3) as Complete
FROM QueryCount2a ) a WHERE a.DateCompl=date()-1 a.CodeValue = rm.CodeValue) as [yournewcolumnname]
FROM
QueryCount2 AS rm
GROUP BY rm.CodeValue;
|