Greetings All,
I am trying to write a simple query to list what machines are in Maintenance Mode and how long they have been in Maintenance Mode. Below is my attempt at it. I keep getting the whole history for a machine and not the most recent. Can anybody help me figure this out please, it's driving me nuts lol. Many thanks as always for any help.

_____________

--Get UTC Time
declare @UTCtd AS datetime
set @UTCtd = getutcdate()

--Get Today's Date and Time
declare @TodayTD AS datetime

set @TodayTD = GETDATE()

--Get Time Zone Informaiton
declare @TimeDif as int
set @TimeDif = DATEDIFF(hh, getutcdate(), getdate())

select
o.ObjID,
o.Name,
m.Operation,
LogTime = min(m.LogTime),
--DATEADD (HH,@TimeDif,dbo.fnSQLDateTime (m.LogTime)) as LogTime,
DATEDIFF(mi, @TodayTD, (DATEADD (HH,@TimeDif,dbo.fnSQLDateTime (m.LogTime)))) * -1 as DataAgeMinutes
from
dbo.Object as o with (NOLOCK)
join dbo.MachineMntHistory as m with (NOLOCK) on o.ObjID = m.MCMachineObjID
where
o.Status & 0x00004000 != 0
and
m.Operation = 'Start-Maintenance'

group by ObjID, Name, Operation, LogTime