drop table #a
drop table #b
create table #a( dt1 datetime,dt2 datetime)
insert into #a select '2013-01-01','2013-01-31'
insert into #a select '2013-02-10','2013-02-20'
insert into #a select '2013-03-05','2013-03-31'
insert into #a select '2013-04-01','2013-04-30'
create table #b( dt1 datetime,dt2 datetime)
insert into #b select '2013-01-10','2013-01-15'
insert into #b select '2013-02-05','2013-02-10'
insert into #b select '2013-03-06','2013-03-20'
select * from #a
select * from #b
#b 中的日期 若 不包含在#a 中则返回 1,反之返回0
最后结果
2013-01-10 2013-01-15 1
2013-02-05 2013-02-10 0
2013-03-06 2013-03-20 1
------解决方案--------------------
use tempdb
go
create table #a( dt1 datetime,dt2 datetime)
insert into #a select '2013-01-01','2013-01-31'
insert into #a select '2013-02-10','2013-02-20'
insert into #a select '2013-03-05','2013-03-31'
insert into #a select '2013-04-01','2013-04-30'
create table #b( dt1 datetime,dt2 datetime)
insert into #b select '2013-01-10','2013-01-15'
insert into #b select '2013-02-05','2013-02-10'
insert into #b select '2013-03-06','2013-03-20'
go
select
b.*,Flag=case when a.dt1 is not null then 1 else 0 end
from #b as b
left join #a as a on a.dt1<=b.dt1 and a.dt2>=b.dt2
/*
dt1 dt2 Flag
2013-01-10 00:00:00.000 2013-01-15 00:00:00.000 1
2013-02-05 00:00:00.000 2013-02-10 00:00:00.000 0
2013-03-06 00:00:00.000 2013-03-20 00:00:00.000 1
*/