日期:2014-05-17 浏览次数:20739 次
With dt1 as(
Select 0 as id, '2013-01-01' as c1,'2013-01-04' as c2 union all
Select 1,'2013-01-02','2013-01-03' union all
Select 2,'2013-01-03','2013-01-07' union all
Select 3,'2013-01-04','2013-01-06' union all
Select 4,'2013-01-05','2013-01-08' union all
Select 5,'2013-01-06','2013-01-11' union all
Select 6,'2013-01-07','2013-01-14' union all
Select 7,'2013-01-08','2013-01-12' union all
Select 8,'2013-01-09','2013-01-10' union all
Select 9,'2013-01-10','2013-01-11' union all
Select 10,'2013-01-11','2013-01-13' union all
Select 11,'2013-01-12','2013-01-15' union all
Select 12,'2013-01-13','2013-01-16' union all
Select 13,'2013-01-14','2013-01-15' union all
Select 14,'2013-01-15','2013-01-18' union all
Select 15,'2013-01-16','2013-01-16' union all
Select 16,'2013-01-17','2013-01-20'
),
dt2 as ( Select '2013-01-10' as c1 )
Select id, DATEDIFF(DD,c1,c2) '间隔',c1,c2,
case DATEPART(weekday, c1 ) when 1 then '日'
when 2 then '一' when 3 then '二'
when 4 then '三' when 5 then '四'
when 6 then '五' when 7 then '六' end as 'C1_week',
case DATEPART(weekday, c2 ) when 1 then '日'
when 2 then '一' when 3 then '二'
when 4 then '三' when 5 then '四'
when 6 then '五' when 7 then '六' end as 'C2_week' from dt