An employee is assigned every day to a team to fullfill tasks. Usually you stick to the team for some days. I want to get a report of the timeline that marks the participation in the groups like this:
Team from to
A 2021-01-01 2021-01-02
B 2021-01-03 2021-01-05
C 2021-01-06 2021-01-07
B 2021-01-08 2021-01-10
If I group by Teams to get min (from) and max (to) it doesn't take into account that a period is defined by the first and the last time someone is continously assigned to that team.
IF OBJECT_ID('tempdb..#temp') IS NOT NULL
DROP TABLE #temp
CREATE TABLE #temp (date DATETIME, Team nvarchar(1))
insert into #temp (date, Team) values ('1.1.2021', 'A')
insert into #temp (date, Team) values ('1.2.2021', 'A')
insert into #temp (date, Team) values ('1.3.2021', 'B')
insert into #temp (date, Team) values ('1.4.2021', 'B')
insert into #temp (date, Team) values ('1.5.2021', 'B')
insert into #temp (date, Team) values ('1.6.2021', 'C')
insert into #temp (date, Team) values ('1.7.2021', 'C')
insert into #temp (date, Team) values ('1.8.2021', 'B')
insert into #temp (date, Team) values ('1.9.2021', 'B')
insert into #temp (date, Team) values ('1.10.2021', 'B')
If I do:
select Team, min(date), max(date)
from #temp
group by Team
it just returns 3 rows as it does not look at the repetition. How do I achieve this with an older express version 10.5
Hope I did explain my point.
Thanks, Martin