Dear All Thanks for your Responses...
Achieved Workable solution for now...
please revert if any optimization or effective is available by Select query only...
Query:
DECLARE
@MinDate DATE = '2015-12-12',
@MaxDate DATE = '2018-12-12';
SELECT FT.Row_Number,FT.Endfiscalyear-1 as StartFiscalYear,
FT.Endfiscalyear, FT.DayDifference,
CASE WHEN FT.Row_Number = 1 THEN DATEADD(DD,-FT.DayDifference+1,FT.EndDate)
ELSE DATEADD(day,1,DATEADD(YEAR,-1,FT.EndDate ))
END as startDate , CASE WHEN FT.Row_Number > 1 AND FT.DayDifference < 365 THEN @MaxDate
ELSE FT.EndDate END as EndDate
from (SELECT ROW_NUMBER() OVER(ORDER BY Endfiscalyear) AS Row_Number,
Endfiscalyear,Count(UT.dt) as DayDifference,
DATEFROMPARTS (Endfiscalyear-1,04,01) as StartDate,
DATEFROMPARTS (Endfiscalyear,03,31) as EndDate
from (select st.dt,year(dateadd(month, -3 + 12, st.dt)) as Endfiscalyear
from(SELECT TOP (DATEDIFF(DAY, @MinDate, @MaxDate) + 1)
DATEADD(DAY, ROW_NUMBER() OVER(ORDER BY a.object_id) - 1, @MinDate) as dt
FROM sys.all_objects a CROSS JOIN sys.all_objects b) as st) as UT
Group BY Endfiscalyear) as FT
Output:
RN SFY EFY DayDiff stDate EndDate
1 2015 2016 111 2015-12-12 2016-03-31
2 2016 2017 365 2016-04-01 2017-03-31
3 2017 2018 365 2017-04-01 2018-03-31
4 2018 2019 256 2018-04-01 2018-12-12