[英]How to compare datetime range between 4 datetime columns in SQL Server
我的表way_point
有4个日期时间列。 四列是
scheduled_a, checkin_time, no_later_than, no_earlier_than
现在我想查看scheduled_a
, checkin_time
值是否介于no_later_than
和no_earlier_than
列的范围之间。
这是我写的代码,但是我收到了这个错误:
在预期条件的上下文中指定的非布尔类型的表达式,在'和'附近。
码:
select
customer_id, position
from
way_points
where
position = 2
and [scheduled_a] and [checkin_time] between [no_later_than] and [no_earlier_Than]
Position
在这里是另一个列,我必须在其中使用条件。 但大部分时间我都被困在比较日期时间列。
知道我哪里错了吗? 谢谢。
你快到了。 您需要将其拆分为两个不同的条件。 不能说no_later_than或no_earlier_than是否更大。 在第一个参数between
需要较小的一个。 例如,如果no_later_than = '2016-02-22'
且no_earlier_than = '2016-02-23'
则no_later_than
是较小的参数。
select customer_id,position
from way_points where position=2
and [scheduled_a] between no_later_than and [no_earlier_than]
and [checkin_time] between no_later_than and [no_earlier_than]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.