It would help if you provided sample data - I have put this together:
--==== Create a test table
Declare @testTable Table (
IncidentNumber int
, IncidentDate datetime
, Agency char(3)
, Unit char(2)
, DispatchTime datetime
, EnrouteTime datetime
, OnSceneTime datetime
, ClearTime datetime
);
--==== Populate test table with sample data
Insert Into @testTable (IncidentNumber, IncidentDate, Agency, Unit, DispatchTime, EnrouteTime, OnSceneTime, ClearTime)
Values (1, '2021-03-01 00:00:00.000', 'EMS', 'M1', '2021-03-01 00:01:00.000', '2021-03-01 00:02:00.000', '2021-03-01 00:15:00.000', '2021-03-01 00:30:00.000')
, (2, '2021-03-01 09:00:00.000', 'EMS', 'M1', '2021-03-01 09:01:00.000', '2021-03-01 09:02:00.000', Null, '2021-03-01 09:05:00.000')
, (2, '2021-03-01 09:00:00.000', 'EMS', 'M1', '2021-03-01 09:04:00.000', '2021-03-01 09:05:00.000', '2021-03-01 09:10:00.000', '2021-03-01 09:30:00.000')
, (3, '2021-03-01 10:00:00.000', 'EMS', 'M1', '2021-03-01 10:02:00.000', '2021-03-01 10:03:00.000', Null, '2021-03-01 10:00:00.000')
, (4, '2021-03-01 12:59:00.000', 'EMS', 'M1', '2021-03-01 13:00:00.000', Null, Null, '2021-03-01 13:02:00.000')
, (4, '2021-03-01 12:59:00.000', 'EMS', 'M1', '2021-03-01 13:01:00.000', '2021-03-01 13:02:00.000', Null, '2021-03-01 13:15:00.000')
, (4, '2021-03-01 12:59:00.000', 'EMS', 'M1', '2021-03-01 13:14:00.000', '2021-03-01 13:20:00.000', '2021-03-01 13:20:00.000', '2021-03-01 13:40:00.000');
--==== Solution
Select tt.IncidentNumber
, tt.IncidentDate
, tt.Agency
, tt.Unit
, tt.DispatchTime
, tt.EnrouteTime
, tt.OnSceneTime
, tt.ClearTime
, TimeToOnScene = datediff(second, tt.IncidentDate, tt.OnSceneTime)
, MinOnSceneTime = min(tt.IncidentDate) over(Partition By tt.IncidentNumber)
, MaxOnSceneTime = max(tt.OnSceneTime) over(Partition By tt.IncidentNumber)
, TotalOnSceneTime = datediff(second, min(tt.IncidentDate) over(Partition By tt.IncidentNumber), max(tt.OnSceneTime) over(Partition By tt.IncidentNumber))
From @testTable tt;
Given the above information - what are you looking for as expected results? Your narrative describes additional columns not shown - no idea how that fits in with the expected solution.
Incident 3 does not have an OnSceneTime for any unit...how would that be calculated?
I have included some columns I think you are looking for - but not sure it is correct.