日期:2014-05-17 浏览次数:20441 次
create table tb (date_time datetime)
insert tb select '2012-09-01' union select '2012-09-02' union select '2012-09-10' union select '2012-09-13'
go
select * from tb
/*
date_time
2012-09-01 00:00:00.000
2012-09-02 00:00:00.000
2012-09-10 00:00:00.000
2012-09-13 00:00:00.000
*/
declare @sdate datetime
declare @edate datetime
set @sdate = '2012-09-01'
set @edate = '2012-09-13'
select MAX (dd)dd from (
select
convert(varchar(10),dateadd(dd,num,@sdate),120) dd
from
(select isnull((select count(1) from sysobjects where id <t.id),0) as num from sysobjects t) a
where
dateadd(dd,num,@sdate) <=@edate )a
where dd not in (select date_time from tb )
/*
dd
2012-09-12
*/