Last post Dec 10, 2018 07:28 AM by Rohan Kshirsagar
Dec 06, 2018 10:30 AM|Rohan Kshirsagar|LINK
This is an Input Table
This is an Output Table which is required
Can any one suggest me how to solve this problem using SQL Server. Please do provide me a right way to solve this problem.
Dec 07, 2018 03:27 PM|Brando ZWZ|LINK
Hi Rohan Kshirsagar,
According to your description, I still couldn't understand your requirement clearly.
Why the start date should be 2011 but the end date will be 2001?
Does these date has the relationship? We just combine the same month's date?
If you could post more details information, it will be more easily for us to understand the issue and find out the solution.
Dec 10, 2018 07:28 AM|Rohan Kshirsagar|LINK
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.
;with cte as (
select Domain_Id, Starting_Date, End_Date
select t.Domain_Id, cte.Starting_Date, t.End_Date
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)
select DISTINCT Domain_Id, Starting_Date, max(End_Date) enddate
group by Domain_Id, Starting_Date
order by Domain_Id, Starting_Date;
select * from Que_Date