时间范围介于两次之间

编程入门 行业动态 更新时间:2024-10-27 14:18:52
本文介绍了时间范围介于两次之间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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!

更多推荐

时间范围介于两次之间

本文发布于:2023-10-27 03:49:47,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1532222.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:两次   时间

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!