第一个问题
你只需要让最小的开始日期大于你的开始日期,让最大的结束日期小于你的结束日期,同时这里限制结束日期不为空(因为结束日期为空
的数据只需要判断开始日期即可),提供SQL语句
where startdate>'2008-10-11 01:00:00' or (stopdate <'2008-10-11 21:00:00' and stopdate is not null
第二个问题
你就是想取结束日期为最大的纪录,同时开始时间限制在你输入的时间以前(不知道我的理解有没有问题)
SQL:
SQLServer  
select top 1 * from table where startdate<'2008-10-11 17:00:00' order by stopdate desc
DB2
select * from table wehre startdate<'2008-10-11 17:00:00' fetch first 1 rows only order by stopdate desc