当前位置: 代码迷 >> Sql Server >> 时间求交集解决办法
  详细解决方案

时间求交集解决办法

热度:85   发布时间:2016-04-27 14:25:31.0
时间求交集
有表Tab_A里面T字段里面存储值从8:00,8:30,9:00.....一直到18:00 ,值固定。
输入开始时间,结束时间,输入的格式为 0:00...5:30....24:00 。
如何取得输入的开始时间、结束时间和Tab_A表里面T字段比较获得交集。

------解决方案--------------------
SQL code
select  *  from  Tab_A where T >=开始时间 and T<=结束时间
------解决方案--------------------
between ..and ..
------解决方案--------------------
SQL code
where T between 开始时间 and  结束时间
------解决方案--------------------
先获取到开始时间,结束时间
[email protected],以逗号区分开始时间,结束时间,例如:'0:00,5:30'

select * from tab_a where 
cast(T as datetime) between case(left(@s , charindex(@s,',') - 1) as datetime) and cast(substring(@s , charindex(@s,',') + 1 , len(@s)) as datetime)
  相关解决方案