SQL抓取每天日期

如下:

drop table tempdate
declare @sdate datetime
declare @endtime datetime
set @sdate = '2000/1/1'
set @endtime='2015/1/31'
select DATEADD(dd,ROW_NUMBER() over( order by ''),@sdate) as date  into tempdate from master..spt_values where type = 'P' and DATEADD(dd,number,@sdate) <= DATEADD(mm,0,@endtime)

select * from master..spt_values where type='P'

select a.date,count=case when b.count is null then 0 else b.count end from tempdate a
left join (

select '2015/1/1' as data,'1' as count
union all
select '2015/1/2' as data,'2' as count
union all
select '2015/1/3' as data,'3' as count
union all
select '2015/1/4' as data,'4' as count
union all
select '2015/1/5' as data,'5' as count) b on a.date=b.data


你可能感兴趣的:(sql,抓取每天日期)