一條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))

結果:spa

 

返回帶有年月日的日期3d

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))

結果:code

相關文章
相關標籤/搜索