SQL抓取每天日期

时间:2015-01-20 18:22:27   收藏:0   阅读:245

如下:

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


本文出自 “倔強的蝸牛” 博客,请务必保留此出处http://5090844.blog.51cto.com/5080844/1606189

原文:http://5090844.blog.51cto.com/5080844/1606189

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!