---------------------------------
--获取指定日期所在月份的日期列表
---------------------------------
declare @date datetime
set @date='2009-03-05'
select [day]=convert(varchar,DATEADD(mm,DATEDIFF(mm,0,@date),0)+number,112)
from master..spt_values
where type='P'
and number< datediff(dd,@date,dateadd(mm,1,@date))
-----------------------------
--获取起止日期中所有月份列表
----------------------------
DECLARE @startdate DATE,
@enddate DATE
SET @startdate='2014-01-01'
SET @enddate='2014-12-01'
--GETDATE()获取当前时间
SELECT DATEADD(mm, number, @startdate)
FROM master..spt_values
WHERE type = 'P'
AND number <= DATEDIFF(mm, @startdate, @enddate)