Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Find months between 2 dates

Author  Topic 

Fathima
Starting Member

1 Post

Posted - 2008-04-02 : 23:59:40
hai friends,

I have a problem in finding month and year sequence between to date. one date is minimum date for example march 2005 and one maximum date is today's date april 2008. I need output of month between these years like this

March 2005

April 2005

May 2005

......

January 2006

...

December 2007

January 2008

.....
April 2008



Can any one help me to develop a stored procedure to produce this output...



Thanks in advance,
Abilina

pravin14u
Posting Yak Master

246 Posts

Posted - 2008-04-03 : 01:31:36
CREATE PROCEDURE PRINTDATE
@StartDate DATETIME,
@EndDate DATETIME
AS
WHILE @StartDate<=@EndDate
BEGIN
PRINT datename(mm,@StartDate) + '-'+datename(yy,@StartDate)
SET @StartDate=DATEADD(month,1,@StartDate)
END





Prakash.P
The secret to creativity is knowing how to hide your sources!
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-04-03 : 01:49:28
[code]SELECT DATENAME(mm,DATEADD(mm,number,@StartDate)) + ' ' + DATENAME(yy,DATEADD(mm,number,@StartDate))
FROM master..spt_values
WHERE type='p' AND number BETWEEN 0 AND DATEDIFF(mm,@StartDate,@EndDate)[/code]

where @StartDate AND @EndDate are your two dates

Go to Top of Page
   

- Advertisement -