码迷,mamicode.com
首页 > 数据库 > 详细

SQL抓取每天日期

时间:2015-01-20 18:25:15      阅读:227      评论:0      收藏:0      [点我收藏+]

标签: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


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

SQL抓取每天日期

标签:sql抓取每天日期

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!