The Above solution i have modified here check this :
CREATE FUNCTION [dbo].FUN_GETMONTH(@date1 datetime, @date2 datetime)
RETURNS VARCHAR(1000)
AS
BEGIN
declare @tmp varchar(MAX)
SET @tmp = ''
;with cte as (
select datename(month,@date1) as [Month_Name],@date1 as dat
union all
select datename(month,DateAdd(Month,1,dat)),DateAdd(Month,1,dat) from cte
where convert(char(6),DateAdd(Month,1,dat),112) <= convert(char(6),@date2,112))
select @tmp = @tmp + CASE WHEN [Month_Name]='01' THEN 'JAN'
WHEN [Month_Name]='02' THEN 'FEB'
WHEN [Month_Name]='03' THEN 'MAR'
WHEN [Month_Name]='04' THEN 'APR'
WHEN [Month_Name]='05' THEN 'MAY'
WHEN [Month_Name]='06' THEN 'JUN'
WHEN [Month_Name]='07' THEN 'JUL'
WHEN [Month_Name]='08' THEN 'AUG'
WHEN [Month_Name]='09' THEN 'SEP'
WHEN [Month_Name]='10' THEN 'OCT'
WHEN [Month_Name]='11' THEN 'NOV'
WHEN [Month_Name]='12' THEN 'DEC' END + ', ' from CTE
option (maxrecursion 0)
RETURN @tmp;
END
DECLARE @TBL TABLE
(
STRARTDATE DATETIME,
ENDDATE DATETIME
)
INSERT INTO @TBL(STRARTDATE, ENDDATE)
SELECT '2014-01-20', '2014-04-20'
UNION ALL
SELECT '2014-05-20', '2014-09-20'
UNION ALL
SELECT '2014-07-20', '2014-07-20'
UNION ALL
SELECT '2014-06-20', '2014-11-20'
select STRARTDATE,ENDDATE, dbo.FUN_GETMONTH(STRARTDATE, ENDDATE) AS MONTHS from @TBL