简体   繁体   English

在 MS Access DB 查询中用于日期比较的运算符之间无法正常工作

[英]Between operator for date comparison not working properly in MS Access DB query

I have simple query as我有简单的查询

Select *
from myTable tran

Where  tran.Party = 13  
AND  
Format(TransactionDate,'dd-mmm-yyyy') BETWEEN #07-Jan-2020# AND #11-Feb-2020# 

Which returns just one record where transaction date is "07-Jan-2020" and not other records which are falling between these dates.它只返回一个交易日期为“07-Jan-2020”的记录,而不是落在这些日期之间的其他记录。

Update更新

在此处输入图片说明

Update 2:更新 2:

Instead of between operator if I use 'Greater Than' && 'Less Than' operator:如果我使用“大于”&&“小于”运算符,而不是在运算符之间:

Select * from CylinderTransactions tran

Where  tran.Party = 13  AND
Format(TransactionDate,'dd-mm-yyyy') >= #07-Jan-2020# 
AND Format(TransactionDate,'dd-mm-yyyy') <= #11-Feb-2020# 

Than it gets 3 records one from 7th Jan and 2 from 11th Feb, but still one record of 15th Jan (Please refer previous snapshot of actual data.比它得到 3 条记录,一条是 1 月 7 日,2 条是 2 月 11 日,但仍然是 1 月 15 日的一条记录(请参阅之前的实际数据快照。

Filter on the date value itself and never use literal months:过滤日期值本身,从不使用文字月份:

Where  
    tran.Party = 13  
    AND
    TransactionDate BETWEEN #2020/01/07# AND #2020/02/11# 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM