• I have to insert data into the table at the end of each quarter for the past 10 years.

    For now i am able to insert data for the past 10 years.but i need it for quarterly.

    -- Set @EOM to end-of-last-quarter date

    DECLARE @EOM datetime

    SET @EOM = CAST(YEAR(GETDATE()) as varchar(4)) + '-'

    + CAST((MONTH(GETDATE())-1) / 3 * 3 + 1 AS varchar)

    + '-01'

    SET @EOM = DATEADD(day,-1,@EOM)

    --SET @EOM = '03-31-2010' -- For Testing Purpose

    --PRINT @EOM

    --Table to Include Last 10 years Worth of Sales Amt data at the End of Each Year

    Declare @StartDate datetime

    Declare @EndDate datetime

    SET @StartDate = CONVERT(DATETIME, CAST(YEAR(@EOM)-10 as varchar(4)) + '-01-01',120)

    SET @EndDate = DATEADD(year,1,@StartDate-1)

    --PRINT @Startdate

    --PRINT @EndDate

    --Loop to retrieve past 10 years worth of Data at the end of each year

    WHILE @EndDate < @EOM

    BEGIN

    SET @StartDate = DATEADD(Year,1,@StartDate)

    SET @EndDate = DATEADD(Year,1,@EndDate)

    IF @EndDate > @EOM

    SET @EndDate=@EOM

    --Insert into Table ---- @EndDate

    -- PRINT CONVERT(varchar(11),@StartDate,113) + ' - ' + CONVERT(varchar(11),@EndDate,113)

    End