Splitting time from same column and storing into 2 column and finding difference between those 2 columns in sql server.
select SourceName,Active,EventTimeStamp,
case when Active=1
then EventTimeStamp END as ActiveTime,
case when Active=0
then EventTimeStamp END as InactiveTime
from dbo.AllEvent
where SourceName='R2_20'
order by SourceName
;
sname active EventTimeStamp Active Inavtive
R2_20 1 14:51.9 14:51.9 NULL
R2_20 0 14:53.9 NULL 14:53.9
R2_20 1 15:05.9 15:05.9 NULL
R2_20 0 15:07.9 NULL 15:07.9
R2_20 1 15:15.9 15:15.9 NULL
R2_20 0 15:17.9 NULL 15:17.9
R2_20 1 15:26.0 15:26.0 NULL
R2_20 0 15:28.0 NULL 15:28.0
R2_20 1 15:36.0 15:36.0 NULL
R2_20 0 15:38.0 NULL 15:38.0