女士访问查询中的日期过滤(有趣) [英] Date Filtering in Ms Access Query (Interesting)
问题描述
它看起来像样本,但我找不到它是什么?
Its look like the sample but I can't find what this is?
这就是我想要的最终结果=>
Here are what i want final result =>
这是我的查询=>
Select
a.staffname,
a.staffno,
a.cntname
From [Clisys] a
where
CDate([a.acdate]) <= #02/08/2018# and
CntNo='H0128C' and
[a.JobCode] like '1**/2018' and
[a.acdate] is Not Null
但是问题是当我这样选择时,我什么也没得到.但是当我改变原因在哪里=>
But problem is when i select like that, I get nothing. But when i change where cause like that=>
where
CDate([a.acdate]) <= #02/08/2019# and
CntNo='H0128C' and
[a.JobCode] like '1**/2018' and
[a.acdate] is Not Null
我得到了我想要的东西,但是为什么我选择2018年后无法正常工作呢?
I get what i want.But why if i select with 2018 is not working?
推荐答案
始终将日期作为日期而不是字符串,数字,异常处理.
Always handle dates as dates, not strings, not numbers, no exceptions.
当您编写SQL时,请使用正确的语法.日期值的文本表达式必须类似于mm/dd/yyyy或yyyy/mm/dd.
And when you write SQL, use the correct syntax. The text expression for a date value must be like mm/dd/yyyy or yyyy/mm/dd.
您确实使用了dd/mm/yyyy,因此您的日期读为2018-02-08.因此使用:
You did use dd/mm/yyyy, thus your date was read as 2018-02-08. So use:
CDate([a.acdate]) <= #2018/08/02#
,您的查询将按预期运行.
and your query will run as expected.
这篇关于女士访问查询中的日期过滤(有趣)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!