Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
214 views
in Technique[技术] by (71.8m points)

vb.net - 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 =>

enter image description here

Here is my query=>

 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

I get what i want.But why if i select with 2018 is not working?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Always handle dates as dates, not strings, not numbers, no exceptions.

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.

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...