SQLServer一条SQL查出当月的每一天
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))
结果: