Results 1 to 4 of 4
  1. #1
    stenman is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Sep 2013
    Posts
    8

    display odd\even numbers

    Would like to create a count for counting odd and even numbers in a field. Let say I have field1 and field2 declared as number and here I have 100 numbers in each row. How to create a sql in access counting how many odd and even numbers are represented in each field, the best would have two new fields(one for odd and one for even per row)?



    The sql should be a "inner-sql" since I already have the "outer-sql" doing something else!

  2. #2
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Let say I have field1 and field2 declared as number and here I have 100 numbers in each row.
    Not quite clear what you mean by this. Do you mean you have 100 numbers entered in a single field (i.e. field1)? If so, how are they separated?
    Or do you have 100 different records, each with two field values, field1 and field2?

  3. #3
    stenman is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Sep 2013
    Posts
    8
    exactly, I have 100 different records with two field values, field1 and field2...

  4. #4
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    You could write an IIF statement using the MOD function to check for evens/odds, returning a 1 or zero, and then SUM those calculations in an Aggregate Query to get the counts.
    Something like this:
    Code:
    SELECT 
        Sum(IIf([Field1] Mod 2=0,1,0)) AS Field1_Evens, 
        Sum(IIf([Field1] Mod 2=1,1,0)) AS Field1_Odds, 
        Sum(IIf([Field2] Mod 2=0,1,0)) AS Field2_Evens, 
        Sum(IIf([Field2] Mod 2=1,1,0)) AS Field2_Odds
    FROM 
        MyTable;

Please reply to this thread with any new information or opinions.

Similar Threads

  1. same numbers = differnet numbers?
    By mike02 in forum Queries
    Replies: 1
    Last Post: 07-17-2013, 03:40 PM
  2. Replies: 4
    Last Post: 01-25-2013, 01:57 PM
  3. Replies: 1
    Last Post: 11-29-2011, 08:43 AM
  4. Syntax to have phone numbers display
    By Juan4412 in forum Queries
    Replies: 7
    Last Post: 09-09-2011, 06:41 AM
  5. Report control of a field display/no display
    By systems013 in forum Reports
    Replies: 5
    Last Post: 02-01-2010, 09:44 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums