467,913 Members | 1,821 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,913 developers. It's quick & easy.

date Filter on form (3 months, non consecutive)

64KB
Hi,
would like to filter a form with a form filter, the form has 12 buttons (12 months) and would like to retrieve records depending on which button is pressed.
This filter example works, it shows records from Jan, Feb, and Apr 2021 but I don't get why it shows them all. Should't it show just one month because I used OR?


Month([DateProcessed])=1 AND Year(DateProcessed)=2021 OR Month([DateProcessed])=2 AND Year(DateProcessed)=2021 OR Month([DateProcessed])=4 AND Year(DateProcessed)=2021
3 Weeks Ago #1

✓ answered by isladogs

Add brackets around each section to clarify what the code is doing

Expand|Select|Wrap|Line Numbers
  1. (Month([DateProcessed])=1 AND Year(DateProcessed)=2021) 
  2. OR (Month([DateProcessed])=2 AND Year(DateProcessed)=2021) 
  3. OR (Month([DateProcessed])=4 AND Year(DateProcessed)=2021)
Now can you see why it will show results for each of the months listed

  • viewed: 1420
Share:
2 Replies
isladogs
Expert 128KB
Add brackets around each section to clarify what the code is doing

Expand|Select|Wrap|Line Numbers
  1. (Month([DateProcessed])=1 AND Year(DateProcessed)=2021) 
  2. OR (Month([DateProcessed])=2 AND Year(DateProcessed)=2021) 
  3. OR (Month([DateProcessed])=4 AND Year(DateProcessed)=2021)
Now can you see why it will show results for each of the months listed
3 Weeks Ago #2
NeoPa
Expert Mod 16PB
Hi Neruda.

I think what you're missing in your appreciation of how the SQL WHERE clause works is that it :
  1. ISN'T - an overall description of the logic of which records to get such as :
    Get me all records WHERE A AND/OR all records WHERE B.
  2. IS - a description of the logic for each record :
    Get me all records WHERE (For each record) A AND/OR B.
In your case, assuming I were to choose months Jan & Apr (Forgetting about Year for now.), then I would choose every record which was Jan AND every record which was Apr, because - at an individual record level - Jan OR Apr evaluated to True.

Does that make the logic clearer?
3 Weeks Ago #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by khalid_uk | last post: by
3 posts views Thread by Nathan Bloomfield | last post: by
1 post views Thread by mrityunjay11 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.