473,405 Members | 2,445 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Query criteriea for even/odd numbers

I need the syntax for limiting query results to either even or odd numbers, depending on certain conditions.

Any help is appreciated.

Thanks,
ang
Feb 22 '07 #1
6 22569
Rabbit
12,516 Expert Mod 8TB
Well... what are these numbers and what are these conditions?

As a general answer, you can use If (Number Mod 2) = 1 Then/Else.
Feb 22 '07 #2
Well... what are these numbers and what are these conditions?

As a general answer, you can use If (Number Mod 2) = 1 Then/Else.
I have used DatePart to number the weeks of the year. This is in a field named Week. The other field used is Hourly Status.

If a person is a Salaried employee, their pay period ending is an even week. If hourly, an odd week. In non-code terms:

=If Hourly Status = "S" and if the current week is even, show records for this week and last week. But if Hourly Status = "S" and the current week is odd, show records for this week only.

The opposite for all other entries into the Hourly Status field:

=If Hourly Status IsNot "S" and if the current week is odd, show records for this week and last week. But if Hourly Status IsNot "S" and the current week is even, show records for this week only.


Can this all be done with one conditional statement?

Thanks.
Feb 22 '07 #3
ADezii
8,834 Expert 8TB
I have used DatePart to number the weeks of the year. This is in a field named Week. The other field used is Hourly Status.

If a person is a Salaried employee, their pay period ending is an even week. If hourly, an odd week. In non-code terms:

=If Hourly Status = "S" and if the current week is even, show records for this week and last week. But if Hourly Status = "S" and the current week is odd, show records for this week only.

The opposite for all other entries into the Hourly Status field:

=If Hourly Status IsNot "S" and if the current week is odd, show records for this week and last week. But if Hourly Status IsNot "S" and the current week is even, show records for this week only.


Can this all be done with one conditional statement?

Thanks.
I think it is asking a little too much for a single conditional statement, try this logic:
Expand|Select|Wrap|Line Numbers
  1. Select Case Hourly Status
  2.   Case "S"
  3.       If Week Mod 2 = 0 Then       'even week
  4.          'show Records for this & last week
  5.       Else       'week is odd
  6.          'show Records for this week only
  7.       End If
  8.   Case Else     'not S
  9.       If Week Mod 2 = <> 0 Then       'odd week
  10.          'show Records for this & last week
  11.       Else      'even week
  12.          'show Records for this week only
  13.       End If
  14. End Select
Feb 22 '07 #4
Rabbit
12,516 Expert Mod 8TB
I almost have it working except for one problem:
Expand|Select|Wrap|Line Numbers
  1. SELECT Table1.[Hourly Status], Table1.Name, Table1.WeekWork
  2. FROM Table1
  3. WHERE (((Table1.[Hourly Status])="S") AND ((Table1.WeekWork)=IIf(DatePart("ww",Date()) Mod 2=1,DatePart("ww",Date()),"Value if False"))) 
  4. OR (((Table1.[Hourly Status])<>"S") AND ((Table1.WeekWork)=IIf(DatePart("ww",Date()) Mod 2=1,DatePart("ww",Date()),"Value if False")));
  5.  
The problem is what to put in Value if False.
I've tried "Between (DatePart("ww",Date()) - 1) And DatePart("ww",Date())
I've tried ">= DatePart("ww",Date())-1)"
But nothing works because it see's it as a string rather than as a conditional statement.
Feb 22 '07 #5
I almost have it working except for one problem:
Expand|Select|Wrap|Line Numbers
  1. SELECT Table1.[Hourly Status], Table1.Name, Table1.WeekWork
  2. FROM Table1
  3. WHERE (((Table1.[Hourly Status])="S") AND ((Table1.WeekWork)=IIf(DatePart("ww",Date()) Mod 2=1,DatePart("ww",Date()),"Value if False"))) 
  4. OR (((Table1.[Hourly Status])<>"S") AND ((Table1.WeekWork)=IIf(DatePart("ww",Date()) Mod 2=1,DatePart("ww",Date()),"Value if False")));
  5.  
The problem is what to put in Value if False.
I've tried "Between (DatePart("ww",Date()) - 1) And DatePart("ww",Date())
I've tried ">= DatePart("ww",Date())-1)"
But nothing works because it see's it as a string rather than as a conditional statement.
I ended up doing it this way:

I created a new table named WkNo with two fields WeekNumber and Status. I then populated the table with week numbers from 1 to 52 for the year, and the status is either even or odd, manually input by me.

I then used a DLookUp function in a form to look up the record from the WkNo table where the WeekNumber equals the DatePart of the current week, returning the even or odd in the Status field.

It's a work-around for sure. I wish I knew code better so I wouldn't have to do things like this. If I knew conditional statements better, I considered using If/OR kind of thing to say if wk=2 or 4 or 6 or 8...,even, odd. but I didn't know how that syntax looks.

Thanks anyway for all of your help.
ang
Feb 23 '07 #6
Rabbit
12,516 Expert Mod 8TB
Well, either way you have it working. Let us know if you have any more questions.
Feb 23 '07 #7

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

Similar topics

1
by: Jeff Uchtman | last post by:
If I query a table in MS SQL and know the possibilitys are a response of 1 to 93 but some numbers may not be present yet, how can I do a query for all 93 numbers and show a result even if its zero...
7
by: Melissa | last post by:
I'm trying to create a function that I can put in a query field that will consecutively number the records returned by the query starting at 1 and will start at 1 each time the query is run. So far...
1
by: j.mandala | last post by:
I created a simple link between two tables in a query. TableA has Social Security numbers stored as Long Integer Data. (I imported this table). The Join is between these two fields Table ...
4
by: RBohannon | last post by:
I'm using Access 2000. I currently have a report being generated using the results of a query by form. The form used for this query is an unbound form, frmListDialog. frmListDialog contains...
8
by: Maxi | last post by:
There is a lotto system which picks 21 numbers every day out of 80 numbers. I have a table (name:Lotto) with 22 fields (name:Date,P1,P2....P21) Here is the structure and sample data: ...
96
by: Karen Hill | last post by:
SELECT surgeries.*, animals.* FROM surgeries INNER JOIN animals ON .=. AND WHERE ((.=Date()) Or .=Date()); I'm trying to write a query that joins two table together, animals and surgeries...
2
by: rivka.howley | last post by:
I wrote some code that creates a table with a date/time field at 15-minute intervals. Here's how I create and populate the table With tblDataTemp ..Fields.Append .CreateField("CT_ID", dbLong)...
6
by: Dixie | last post by:
I have asked this question before, but I could not get the suggested solution work. So I will give more details this time. I have an append query that adds several hundred records to a table...
1
by: Warren Thai | last post by:
I am using Access 2003. I need to export data from a query to a .txt file. I know how to do this but however there is a problem with my data being rounded. The numbers in the data have 3 decimal...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.