如何在SQL中查找时间(格式:yymmdd 小时:分钟:秒)是否在时间范围内



有人可以帮我做一个SQL查询吗,该查询将告诉特定时间是否在给定的时间范围内。

start_time = 20140304 11:00:00
end_time   = 20140303 08:00:00

如果我给20140303 07:00:00,它应该说它是否在提到的时间范围内。 对于当前场景,它应该通过并打印"是"

更新这些值是瓦尔查尔格式

下面是

一个where子句:

where (start_time < end_time and @VALUE between start_time and end_time) or
      (start_time > end_time and @VALUE between end_time and start_time)

我假设你想要一个匹配,无论start_time是在end_time之前还是之后。

编辑:

如果你想在select中这样做,那么使用case

select (case when (start_time < end_time and @VALUE between start_time and end_time) or
                  (start_time > end_time and @VALUE between end_time and start_time)
             then 1 else 0
        end) as Flag

最新更新