时间范围介于两次之间 [英] Time range between two times

查看:83
本文介绍了时间范围介于两次之间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Sql server如何选择两列之间的时间范围。任何人都可以尽快解释怎么做



我尝试过:



select * from tablename

where starttime< @starttime

和endtime> @entime

Sql server how to select time range between two columns times. Can any one explain how to do ASAP

What I have tried:

select * from tablename
where starttime < @starttime
and endtime > @entime

推荐答案

当遇到这样的问题时,通常是因为数据库设计错误了。

首先检查列定义:如果starttime和endtime不是DATE,DATETIME或DATETIME2列,则没有与日期相关的查询将起作用,因为它们将被视为基于字符串=的比较。有了这些,整个比较基于两个字符串中的第一个不同字符,因此01-01-2017出现在31-12-2016之前等等。



如果列没问题,请检查参数值:再次这些应该是您的原生表示语言中传递它们的DateTime值,而不是字符串 - 否则SQL必须猜测它们是否为dd-mm-yy ,mm-dd-yy或yy-dd-mm,它经常会出错。



如果一切正常,请查看数据和手动参数值,并检查是否存在符合这两个条件的值。



抱歉,我们不能做任何事情:我们没有访问您的代码或数据!
When you get problems like this, it's often because the database has been designed wrong.
Start by checking the column definitions: if starttime and endtime are not DATE, DATETIME, or DATETIME2 columns, then no date-related queries will work as they will be treated as string =-based comparisons. With those, the entire comparison is based on the first different character in the two strings, so "01-01-2017' comes before "31-12-2016" and so forth.

If the columns are ok, check the parameter values: again these should be DateTime values in your native presentation language that passes them, not strings - otherwise SQL has to "guess" if they are "dd-mm-yy", "mm-dd-yy", or "yy-dd-mm" and it will frequently get it wrong.

If that's all OK, look at the data, and the parameter values manually, and check that some values exist that match both condition.

Sorry, but we can't do any of that: we have no access to your code or data!


这篇关于时间范围介于两次之间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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