日期:2014-05-18 浏览次数:20776 次
create table t_time( studentId int, begin_time datetime, end_time datetime ) truncate table t_time insert t_time select 1,'2010-4-6', '2010-5-6' union all select 2,'2010-4-5', '2010-4-6' union all select 3,'2010-4-6', '2010-4-7' union all select 4,'2010-4-5', '2010-4-9' union all select 5,'2010-5-1', '2010-5-10' union all select 6,'2010-5-5', '2010-5-6' select * from t_time where begin_time <= '2010-5-1' and end_time >'2010-5-1'
------解决方案--------------------
学习了
------解决方案--------------------
use PracticeDB
go
if exists (select 1 from sysobjects where name='tb')
drop table tb
go
create table tb (id int,start_time date,end_time date)
go
insert into tb
select 1,'2010-01-01','2010-01-03' union all
select 2,'2010-04-03','2010-04-06' union all
select 3,'2010-05-01','2010-05-03' union all
select 4,'2010-06-13','2010-06-16'
declare @date varchar(10)
set @date ='05-01'
select id,(case when @date between right(convert(varchar(10),start_time,120),len(convert(varchar(10),start_time,120))-5)
and right(convert(varchar(10),end_time,120),len(convert(varchar(10),end_time,120))-5) then '在' else '不在' end) [在不在内]
from tb
------解决方案--------------------
我帮楼主验证过了