June 2, 2011 at 8:06 am
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)
June 2, 2011 at 9:34 am
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
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply