SELECT min(FlowLogPeriod.MdbDeviceID),
min(DeviceSummary.MeterID),
cast(CONVERT(varchar, FlowLogPeriod.LogPeriodFlowDateTime, 101) as datetime) AS Date,
sum(FlowLogPeriod.AP) as AP,
FROM DeviceSummary
INNER JOIN FlowLogPeriod ON DeviceSummary.MdbDeviceID = FlowLogPeriod.MdbDeviceID
WHERE (DeviceSummary.MeterID IN ('01103-705','01103-706','01103-708')) AND
(FlowLogPeriod.LogPeriodFlowDateTime>= @StartDate) AND
(FlowLogPeriod.LogPeriodFlowDateTime -1 <= @EndDate) AND
(DATEPART(HOUR, FlowLogPeriod.LogPeriodFlowDateTime) = 9)
Group by cast(CONVERT(varchar, FlowLogPeriod.LogPeriodFlowDateTime, 101) as datetime)
|