解决方案 »
- IMAGE 类型如何复制
- 200分,求个sql,同一个表用同一个字段的条件查同一个字段的结果
- 两台服务器同步复制数据,为什么只能复制74行???
- 日期格式问题!在线等!
- 请教,导出数据到excel的T-Sql语句如何在存储过程里添加条件参数。在线等
- 数据库字典表的问题
- 如何让整型和MONEY型长度不够额定长度时就用空格填充???
- SQL Server 2005附加数据库出现的提示
- 原系统是用ACCESS库实现的,现改为SQL,还需要些什么?否则为何总是显示
- 请txlicenhe(马可)接分3
- 求一条sql查询,或几条语句只要能查到这个结果
- 疑难问题:从表中随即取出n条记录,条件是sum(金额)占总金额的30%
--就是一个时间交叉的逻辑判断
--当转化为sql判断的时候,觉得没那么简单吧
create table #test
(
dbtime1 datetime,
dbtime2 datetime
)insert into #test values('2014-6-3','2014-7-3')declare @begindate datetime
declare @enddate datetime
set @begindate='2014-5-7'
set @enddate='2014-9-9'
select case when (COUNT(1)>0) then '交叉'else '不交叉' end as result from #test where
(@begindate<dbtime1 and @enddate>dbtime2)--被包含
or
(@begindate>dbtime1 and @begindate<dbtime2)--后交叉
or
(@enddate>dbtime1 and @enddate<dbtime2)--前交叉
第二,指定的开始时间落在已有的时间段内(后交叉)
第三,指定的结束时间落在已有的时间段内(前交叉)
第四,指定的开始时间落在已有的时间段内,指定的结束时间落在已有的时间段内(前后同时交叉)不过第四种情况归属于第二或者第三种情况,所以sql中只有三个判断条件