UFN_FISCALQUARTER
Return
Return Type |
---|
tinyint |
Parameters
Parameter | Parameter Type | Mode | Description |
---|---|---|---|
@MONTH_FY_ENDS | tinyint | IN | |
@DATE | date | IN |
Definition
Copy
create function BBDW.[UFN_FISCALQUARTER](@MONTH_FY_ENDS tinyint,@DATE date)
returns tinyint
-- Input the Month (1 to 12) the Fiscal Year ends and the Date
-- Returns the Fiscal quarter of the date
as
begin
declare @Q tinyint;
declare @FY_STARTMONTH tinyint;
if @MONTH_FY_ENDS <=0 or @MONTH_FY_ENDS >12
return 0;
if @MONTH_FY_ENDS=12
set @FY_STARTMONTH =1;
else
set @FY_STARTMONTH =@MONTH_FY_ENDS + 1;
set @Q = convert(tinyint, (((12 + datepart(month,@DATE) - @FY_STARTMONTH)% 12 + 1) / 3.0) + 0.75)
return @Q;
end