-- ===================================================== ======
-- Author: <LK>
-- Create Date: <2008-9-19>
-- Description: <used for quarterly statistics>/* returns the start month of the quarter */
-- Call method: Select DBO. sys_getquarterbegindate ('2017-11-1 ')
-- ===================================================== ======
Alter function [DBO]. [sys_getquarterbegindate] (@ month smalldatetime)
Returns smalldatetime
As
-- Function: returns the start month of the quarter.
Begin
Declare @ DT smalldatetime
If month (@ month) <4
Set @ dt = convert (varchar, year (@ month) + '-1-1'
Else
Begin
If month (@ month) <7
Set @ dt = convert (varchar, year (@ month) + '-4-1'
Else
Begin
If month (@ month) <10
Set @ dt = convert (varchar, year (@ month) + '-7-1'
Else
Set @ dt = convert (varchar, year (@ month) + '-10-1'
End
End
Return @ dt
End
-- ===================================================== ======
-- Author: <LK>
-- Create Date: <2008-9-19>
-- Description: * returns the end of the quarter */
-- Call: Select DBO. sys_getquarterenddate ('2017-11-1 ')
-- ===================================================== ======
Alter function [dbo]. [sys_GetQuarterEndDate] (@ month smalldatetime)
RETURNS smalldatetime
AS
-- Function: returns the end month of the quarter.
BEGIN
DECLARE @ dt smalldatetime
If month (@ month) <4
SET @ dt = CONVERT (VARCHAR, YEAR (@ month) + '-3-31'
ELSE
BEGIN
If month (@ month) <7
SET @ dt = CONVERT (VARCHAR, YEAR (@ month) + '-6-30'
ELSE
BEGIN
If month (@ month) <10
SET @ dt = CONVERT (VARCHAR, YEAR (@ month) + '-9-30'
ELSE
SET @ dt = CONVERT (VARCHAR, YEAR (@ month) + '-12-31'
END
END
RETURN @ dt
END