Try this one:
DECLARE @FrDate DATETIME,
@ToDate DATETIME;
Set @FrDate ='2010-05-31 17:38:58.577'
Set @ToDate ='2010-09-01 17:38:58.577'
;WITH MONTHS (date)
AS
(
SELECT @FrDate
UNION ALL
SELECT DATEADD(month,1,date)
from months
where date<=@ToDate
)
SELECT Datename(month,date) AS MONTH FROM MONTHS
Result:
MONTH
-----------------
May
June
July
August
September
(5 row(s) affected)
To get short month name in result you can use the following line instead:
SELECT LEFT(CONVERT(VARCHAR,date,100),3) AS MONTH FROM MONTHS
To get month name in UPPER case you can use UPPER
function for that:
SELECT UPPER(LEFT(CONVERT(VARCHAR,date,100),3)) AS MONTH FROM MONTHS