日期:2014-05-18 浏览次数:20655 次
select ID,Name,WorkName,RBTime,RFTime from incident
select ID,Name,WorkName,RBTime,RFTime from incident create table incident(ID int,Name varchar(32),WorkName varchar(32),RBTime datetime,RFTime datetime) go insert into incident select 1,'ss','sad','2012-03-01','2012-03-01' union all select 2,'ss','sad','2012-03-02','2012-03-02' union all select 3,'ss','sad','2012-03-03','2012-03-03' declare @month_day int set @month_day=datepart(dd,dateadd(dd,-1,dateadd(mm,1,cast(cast(year(getdate()) as varchar)+'-'+cast(month(getdate()) as varchar)+'-01' as datetime)))) declare @month_first_day datetime set @month_first_day= convert(varchar(10),dateadd(dd,-DatePart(day,dateadd(dd,-1,getdate())),getdate()),120) select a.month_day,b.* from ( select convert(varchar(10),dateadd(day,number,@month_first_day),120)as month_day from master.dbo.spt_values where type='p' and number <=@month_day)a left join incident as b on a.month_day=b.RBTime /* month_day ID Name WorkName RBTime RFTime 2012-03-01 1 ss sad 2012-03-01 00:00:00.000 2012-03-01 00:00:00.000 2012-03-02 2 ss sad 2012-03-02 00:00:00.000 2012-03-02 00:00:00.000 2012-03-03 3 ss sad 2012-03-03 00:00:00.000 2012-03-03 00:00:00.000 2012-03-04 NULL NULL NULL NULL NULL 2012-03-05 NULL NULL NULL NULL NULL 2012-03-06 NULL NULL NULL NULL NULL 2012-03-07 NULL NULL NULL NULL NULL 2012-03-08 NULL NULL NULL NULL NULL 2012-03-09 NULL NULL NULL NULL NULL 2012-03-10 NULL NULL NULL NULL NULL 2012-03-11 NULL NULL NULL NULL NULL 2012-03-12 NULL NULL NULL NULL NULL 2012-03-13 NULL NULL NULL NULL NULL 2012-03-14 NULL NULL NULL NULL NULL 2012-03-15 NULL NULL NULL NULL NULL 2012-03-16 NULL NULL NULL NULL NULL 2012-03-17 NULL NULL NULL NULL NULL 2012-03-18 NULL NULL NULL NULL NULL 2012-03-19 NULL NULL NULL NULL NULL 2012-03-20 NULL NULL NULL NULL NULL 2012-03-21 NULL NULL NULL NULL NULL 2012-03-22 NULL NULL NULL NULL NULL 2012-03-23 NULL NULL NULL NULL NULL 2012-03-24 NULL NULL NULL NULL NULL 2012-03-25 NULL NULL NULL NULL NULL 2012-03-26 NULL NULL NULL NULL NULL 2012-03-27 NULL NULL NULL NULL NULL 2012-03-28 NULL N