I am trying to produce a report in SSRS that shows me a number of jobs within each quarter within a financial year. I have the days/months of each companies FY stored in a database, which I use a query to find current or previous FY start/end dates.
DECLARE @FirstDate DATETIME
DECLARE @LastDate DATETIME
DECLARE @CurrentDate DATETIME
DECLARE @CompanyID BIGINT
SET @CurrentDate = GETDATE()
SET @CompanyID = 631
SELECT @FirstDate = CASE WHEN DATEFROMPARTS(Year(@CurrentDate), Month(c.FinancialYearStart), Day(c.FinancialYearStart)) <= GETDATE() THEN
-- We are in the right Year
DATEFROMPARTS(Year(@CurrentDate), Month(c.FinancialYearStart), Day(c.FinancialYearStart))
ELSE
-- we need to go back a year
DATEFROMPARTS(Year(@CurrentDate)-1, Month(c.FinancialYearStart), Day(c.FinancialYearStart))
END
, @LastDate = CASE WHEN DATEFROMPARTS(Year(@CurrentDate), Month(c.FinancialYearStart), Day(c.FinancialYearStart)) <= GETDATE() THEN
-- We are in the right Year
DATEADD(day, -1, DATEADD(year, 1, DATEFROMPARTS(Year(@CurrentDate), Month(c.FinancialYearStart), Day(c.FinancialYearStart))))
ELSE
-- we need to go back a year
DATEADD(day, -1, DATEADD(year, 1, DATEFROMPARTS(Year(@CurrentDate)-1, Month(c.FinancialYearStart), Day(c.FinancialYearStart))))
END
FROM tCompany c
WHERE c.ID = @CompanyID
How can I query each quarters for the FY from the @FirstDate?
E.g. if a companies FY was 01/04 - 31/03 how can I determine each quarter months?
Quarter 1 - Apr, May, Jun Quarter 2 - Jul, Aug, Sept Quarter 3 - Oct, Nov, Dec Quarter 4 - Jan, Feb, Mar