Results 1 to 8 of 8
  1. #1
    rplum is offline Novice
    Windows 8 Access 2013 32bit
    Join Date
    Apr 2016
    Posts
    10

    Greater Than in Query

    Hi Guys,

    Total rookie with Access and just learning. My work is wanting me to build a small database that pulls data from a live table. They want it to pull PAYCODE "Regular Hours", "Overtime Worked" and "Stat Worked" however they want to calculate Regular Hours > 1000 and Overtime Worked and Stat Worked < 1000. I have it pulling Regular Hours > 1000 right now I just don't know how to get it to pull Overtime Worked and Stat Worked < 1000 from the HRS_WORKED field.


    SELECT Transline.PERSONFULLNAME, Transline.HRS_WORKED, Transline.PAYCODENAME
    FROM Transline


    WHERE (((Transline.HRS_WORKED)>1000))
    GROUP BY Transline.PERSONFULLNAME, Transline.HRS_WORKED, Transline.PAYCODENAME
    HAVING (((Transline.PAYCODENAME)="Regular Hours"));


    Thanks!

  2. #2
    JoeM is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Can you post a small sample so we can see that your data looks like, especially all the fields being referenced in your query?
    For each person and each PayCodeName, will there only be one record, or might there be multiple records that need to be added up?

  3. #3
    rplum is offline Novice
    Windows 8 Access 2013 32bit
    Join Date
    Apr 2016
    Posts
    10
    Click image for larger version. 

Name:	Screenshot_2.png 
Views:	10 
Size:	14.6 KB 
ID:	24379Click image for larger version. 

Name:	Screenshot_1.png 
Views:	10 
Size:	29.2 KB 
ID:	24378

  4. #4
    JoeM is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Since you blanked the name field for everyone, we cannot tell what the answer to the question I asked in my previous reply is. So we will have to rely on you to tell us what the answer is. It is very important to know, as it will change how we approach the solution.
    For each person and each PayCodeName, will there only be one record, or might there be multiple records that need to be added up?
    So, for example, let's say we have a person named "Bob".
    Can Bob have multiple Regular Hours entries, or will he only ever have exactly one?
    And is that true for all the different PayCodeName entries?

  5. #5
    rplum is offline Novice
    Windows 8 Access 2013 32bit
    Join Date
    Apr 2016
    Posts
    10
    He can only have one Regular Hours. The same goes with Overtime Worked and Stat Worked.

    Sorry, I have reupload one with names.

    Click image for larger version. 

Name:	Screenshot_1.png 
Views:	8 
Size:	15.1 KB 
ID:	24380

  6. #6
    JoeM is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Try this code:
    Code:
    SELECT 
        Transline.PERSONFULLNAME, 
        Sum(IIf([Transline]![PAYCODENAME]="Regular Hours",[Transline]![HRS_WORKED],0)) AS Regular_Hours, 
        Sum(IIf([Transline]![PAYCODENAME]="Overtime Worked",[Transline]![HRS_WORKED],0)) AS Overtime_Worked, 
        Sum(IIf([Transline]![PAYCODENAME]="Stat Worked 1.5 Hours",[Transline]![HRS_WORKED],0)) AS Stat_Worked_1_5_Hours
    FROM Transline
    GROUP BY Transline.PERSONFULLNAME
    HAVING 
        (((Sum(IIf([Transline]![PAYCODENAME]="Regular Hours",[Transline]![HRS_WORKED],0)))>1000) 
        AND ((Sum(IIf([Transline]![PAYCODENAME]="Overtime Worked",[Transline]![HRS_WORKED],0)))<1000) 
        AND ((Sum(IIf([Transline]![PAYCODENAME]="Stat Worked 1.5 Hours",[Transline]![HRS_WORKED],0)))<1000));

  7. #7
    rplum is offline Novice
    Windows 8 Access 2013 32bit
    Join Date
    Apr 2016
    Posts
    10
    That worked perfectly!!!


    Thanks so much for the help Joe.

  8. #8
    JoeM is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    You are welcome!

    The key was to create a calculated field for each type that either returns the hours (if it is that type) or a 0 (if it is not).
    Then Group the records by Name and sum those calculated fields to get a single line for each Name showing their hours for each type.
    Then simply apply the criteria to those calculated fields.

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

Similar Threads

  1. Replies: 5
    Last Post: 03-12-2015, 05:13 AM
  2. Replies: 11
    Last Post: 04-11-2014, 04:26 PM
  3. Replies: 1
    Last Post: 04-10-2014, 12:55 PM
  4. Replies: 3
    Last Post: 04-09-2013, 09:32 PM
  5. Greater than query
    By noobaccess in forum Access
    Replies: 5
    Last Post: 12-05-2012, 09:18 PM

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