如何在sql server中获取范围时间 [英] How to get range time in sql server

查看:29
本文介绍了如何在sql server中获取范围时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上我想做的是在范围之间移动

Basically what I want try to do is to get shift in range between

已经得到这个地方

where @param_value_from_hour between From_Hour and To_Hour

它在@param_value_from_hour 让我们说 16:00 时起作用,但是如果我必须在 19:00 搜索 @param_value_from_hour 怎么办?

it works when @param_value_from_hour let say 16:00 but what if I have to search @param_value_from_hour with 19:00?

推荐答案

如果逻辑是这样,如果期间的结束早于期间的开始,则假定该期间跨越午夜(如果不是't,我们需要一些其他形式的约定,否则事情就会变得非常模棱两可):

If the logic is that, if the end of the period is earlier than the start of the period then the period is assumed to span midnight (if it isn't, we need some other form of convention or things get hopelessly ambiguous):

where
   (@param_value_from_hour between From_Hour and To_Hour) or
   (To_Hour < From_Hour and
       (@param_value_from_hour < To_Hour or
        From_Hour < @param_value_from_hour)
   )

应该大致得到你想要的(如果需要,将 < 调整为 <=)

Should get approximately what you want (adjust < for <= if required)

这篇关于如何在sql server中获取范围时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆