Increment a month T-SQL Statement

  • Hi

    Can anyone help me write a store procedure to increment a month

    For example

    The current month is January 10 I want to show the last 12 months so from January 10 - December 10.

    Now if the current month is February 10 I want to increment it to show from February 10 - January 11 and so on

    Jan 10, Feb 10, Mar 10, April 10 , May 10, June 10, July 10, Aug 10, Sep 10, Oct 10, Nov 10, Dec 10

    Can anyone help me or provide me with similar examples??

    Thanks in advance

    __________________________________________________________________________________
    Steve J
    Jnr Developer
    BSc(Hon)

  • DECLARE @StartMonth DATETIME = '20100201'

    SELECT NewMonth = DATEADD( month, cnt.number, @StartMonth )

    FROM master.dbo.spt_values cnt

    WHERE cnt.type='P' AND cnt.number <= 9

    _____________________________________________________
    Microsoft Certified Master: SQL Server 2008
    XDetails Addin - for SQL Developers
    blog.sqlxdetails.com - Transaction log myths

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply