[英]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.