How to get activity status that occurred within a interval during start and stop datetime(SQL)(t-SQL

0

Please login or register to vote for this query.

(click on this box to dismiss)

Software Engineering

Q&A for professionals, academics, and students working within the systems development life cycle

declare @events as table(
  [EventName] varchar(100),
  [OccuredAtDatetime] datetime
);
insert into @events
select 'EventA', '2019-07-03 00:14:01' union all
select 'EventA', '2019-07-03 01:14:01' union all
select 'EventA', '2019-07-03 01:34:01' union all
select 'EventB', '2019-07-03 01:13:03';

declare @interval as table(
  [IntervalName] varchar(100),
  [StartTime] datetime,
  [EndTime] datetime
);

insert into @interval
select 'Interval1', '2019-07-03 00:00:00', '2019-07-03 00:30:00' union all
select 'Interval2', '2019-07-03 00:30:00', '2019-07-03 01:00:00' union all
select 'Interval3', '2019-07-03 01:00:00', '2019-07-03 01:30:00' union all
select 'Interval4', '2019-07-03 01:30:00', '2019-07-03 02:00:00';


select * from @events;
select * from @interval;

Enter Parameters

Options:
Switch sites:
loading Hold tight while we fetch your results