前提:d1 < d2
if (select count(*) from table where  d1 < cdate   or   d2 > edate) <> 0 
print '不在'
else
print '在'

解决方案 »

  1.   

    declare @ table (id varchar(20),cdate datetime,  edate datetime)
    insert @ values('aa','2003/02/03','2003/03/12')
    insert @ values('bb','2003/04/30','2003/05/05')
    insert @ values('cc','2003/05/20','2003/05/30')
    declare @startdate datetime,@enddate datetimeselect @startdate='2003/03/13',@enddate='2003/04/10'if exists(select 1 from @ where edate>=@startdate and cdate<=@enddate)
      select '存在'
    else
      select '不存在'select @startdate='2003/04/27',@enddate='2003/05/07'if exists(select 1 from @ where edate>=@startdate and cdate<=@enddate)
      select '存在'
    else
      select '不存在'