---列举指定时间月份
DECLARE @date1 VARCHAR(10) ,
@date2 VARCHAR(10)
SET @date1 = '2010-01-01'
SET @date2 = '2010-09-01'
SELECT CONVERT(VARCHAR(7), CAST(LTRIM(YEAR(@date1)) + '-' + LTRIM(number)
+ '-01' AS DATETIME), 120)
FROM master..spt_values
WHERE type = 'p'
AND number BETWEEN MONTH(@date1) AND MONTH(@date2)
---列举指定时间段日期
select ymd=convert(varchar,cast('2010-01-01' as datetime)+number,23)
from master..spt_values
where type='p'
and number<= datediff(dd,'2010-01-01','2010-09-01') order by ymd desc