Sql Function to display Financial Quarter
Create Function fn_FinancialQuarter(@Date date )Returns Varchar(50)As
BeginDeclare @Quarter Varchar(50)Declare @Month Int = MOnth(@Date)
If(@Month <= 3)BeginSET @Quarter = 'Q-4 ' + Cast(YEAR(DATEADD(Year, -1, @date)) as varchar(10))EndElseBeginSET @Quarter = 'Q ' + Cast(((MONTH(@Date) - 4) / 3) + 1 as varchar(50)) + '-' + cast(YEAR(@date) as varchar(10))EndReturn @QuarterEnd
No comments:
Post a Comment