日期:2014-05-18 浏览次数:20454 次
use tempdb; /* create table A ( [date] date not null, [num] int ); insert into A values ('2009-01-01',1), ('2009-01-02',10), ('2009-01-04',12), ('2009-01-08',20), ('2009-01-09',0), ('2009-01-10',1); */ declare @startdate datetime,@enddate datetime; set @startdate='2009-01-01'; set @enddate='2009-01-31'; select B.day_time,ISNULL(A.num,0) as num from ( select convert(varchar(10),dateadd(day,number,@startdate),120) as day_time from master..spt_values where datediff(day,dateadd(day,number,@startdate), @enddate)>=0 and number>=0 and type='p' ) as B left join A ON A.[date] = B.day_time;