Tuesday, 10 June 2014

Get Quarters StartDate and EndDate from Year

CREATE FUNCTION cal_quarter (@DATE SMALLDATETIME)

    RETURNS INT
    AS
BEGIN
declare @CalendarQuarter int
        IF month(@DATE) in(4,5,6)
            BEGIN
                set @CalendarQuarter =1
            END
        if month(@DATE) in(7,8,9)
            BEGIN
                set @CalendarQuarter =2
            END
        if month(@DATE) in(10,11,12)
            BEGIN
                set @CalendarQuarter =3
            END
        if month(@DATE) in(1,2,3)
            BEGIN
                set @CalendarQuarter =4
            END
return @CalendarQuarter
END

No comments: