select number+1 from master..spt_values where type='p' and DATEADD(day,number, cast(CONVERT(varchar(7),'2013-02-03')+'-01' as datetime))<DATEADD(MONTH,1,cast(CONVERT(varchar(7),'2013-02-03')+'-01' as datetime))
结果:
返回带有年月日的日期
select CAST( CONVERT(varchar(7),'2013-02-03')+'-'+CONVERT(VARCHAR(2),number+1) AS datetime) from master..spt_values where type='p' and DATEADD(day,number, cast(CONVERT(varchar(7),'2013-02-03')+'-01' as datetime))<DATEADD(MONTH,1,cast(CONVERT(varchar(7),'2013-02-03')+'-01' as datetime))
结果:
原文地址:https://www.cnblogs.com/gates/p/5630532.html