
So, if you are working with a simple SQL Server and you don’t have an SSRS or Power BI or additional tools but you need to divide the output per Quarter for the immediate report that your top management laid on you yesterday, you can just use my snippet and complete the details you want with using your data in additional with the table as.
--data time range
DECLARE @StartDate datetime;
DECLARE @EndDate datetime;
SET @StartDate=CONVERT(DATETIME, '2019-11-01', 102);
SET @EndDate = GETDATE();
--report time range
DECLARE @StartReportDate datetime;
DECLARE @EndReportDate datetime;
SET @StartReportDate=CONVERT(DATETIME, '2021-01-01', 102);
SET @EndReportDate = CONVERT(DATETIME, '2022-07-01', 102);
with dateSlices AS ( -- generates date periods for subselects
SELECT
0 As SliceIndex,
@StartReportDate AS SliceStartDate,
DATEADD(MONTH, 3, @StartReportDate) AS SliceEndDate
UNION ALL
SELECT
SliceIndex + 3 As SliceIndex,
DATEADD(MONTH, SliceIndex, @StartReportDate) As SliceStartDate ,
DATEADD(MONTH, SliceIndex +3, SliceStartDate) AS SliceEndDate
FROM DateSlices
WHERE
SliceEndDate <= @EndReportDate
)
SELECT
Distinct(SliceStartDate),
SliceEndDate--,
--SliceIndex
From dateSlices