User-1705074310 posted
Hey @Brando ZWZ I have updated my question would you help me with this.
I have tried and wrote this code but the problem with this code is i am getting an output as given below. But in this output i don't require 2nd Row. So help me to solve this problem.
Domain_Id |
Starting_Date |
End_Date |
1 |
2011-01-01 |
2011-01-15 |
1 |
2011-01-05 |
2011-01-07 |
2 |
2011-05-11 |
2011-05-12 |
2 |
2011-05-13 |
2011-05-14 |
;with cte as (
select Domain_Id, Starting_Date, End_Date
from Que_Date
union all
select t.Domain_Id, cte.Starting_Date, t.End_Date
from cte
join Que_Date t on cte.Domain_Id = t.Domain_Id and cte.End_Date = t.Starting_Date
), cte2 as (
select *, rn = row_number() over (partition by Domain_Id, End_Date order by Domain_Id)
from cte
)
select DISTINCT Domain_Id, Starting_Date, max(End_Date) enddate
from cte2
where rn=1
group by Domain_Id, Starting_Date
order by Domain_Id, Starting_Date;
select * from Que_Date