日期:2014-05-17 浏览次数:20493 次
;with t(id,dt)
as
(
select
number+1 ,
dateadd(dd,number,'2012-11-01')
from
master..spt_values
where
number between 0 and 45
and type='p'
),
m as(
select
dt,
case when dt between getdate() and dateadd(dd,3,getdate()) then '0-3天'
when dt between dateadd(dd,4,getdate()) and dateadd(dd,7,getdate()) then '4-7天'
when dt between dateadd(dd,8,getdate()) and dateadd(dd,15,getdate()) then '8-15天'
when dt between dateadd(dd,16,getdate()) and dateadd(dd,30,getdate()) then '16-30天' end as di
from
t
)
select
*
from
m where di is not null
/*
dt di
----------------------- -------
2012-11-23 00:00:00.000 0-3天
2012-11-24 00:00:00.000 0-3天
2012-11-25 00:00:00.000 0-3天
2012-11-27 00:00:00.000 4-7天
2012-11-28 00:00:00.000 4-7天
2012-11-29 00:00:00.000 4-7天
2012-12-01 00:00:00.000 8-15天
2012-12-02 00:00:00.000 8-15天
2012-12-03 00:00:00.000 8-15天
2012-12-04 00:00:00.000 8-15天
2012-12-05 00:00:00.000 8-15天
2012-12-06 00:00:00.000 8-15天
2012-12-07 00:00:00.000 8-15天
2012-12-09 00:00:00.000 16-30天
2012-12-10 00:00:00.000 16-30天
2012-12-11 00:00:00.000 16-30天
2012-12-12 00:00:00.000 16-30天
2012-12-13 00:00:00.000 16-30天
2012-12-14 00:00:00.000 16-30天
2012-12-15 00:00:00.000 16-30天
2012-12-16 00:00:00.000 16-30天
(21 行受影响)
*/