SELECT CONVERT(VARCHAR(10), DATEADD(dd, number,
CONVERT(VARCHAR(8), GETDATE(), 120)
+ '01'), 120) AS dt
FROM master..spt_values
WHERE type = 'P'
AND DATEADD(dd, number,
CONVERT(VARCHAR(8), GETDATE(), 120)
+ '01') <= DATEADD(dd, -1,
CONVERT(VARCHAR(8), DATEADD(mm,
1, GETDATE()), 120)
+ '01');
转载于:https://www.cnblogs.com/alwaysonline/p/6168617.html