Page 2 of 3 FirstFirst 123 LastLast
Results 16 to 30 of 35
  1. #16
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,743
    I modified the sql to deal with your Date criteria, and to allow for employeeIds in (602,603)
    and WorkIds in (7,10,12)

    The revised SQL is

    Code:
    SELECT [%$##@_Alias].EmployeeID
    ,[%$##@_Alias].WorkcodeID
    ,Sum([%$##@_Alias].SumOfBillableHours) AS SumOfSumOfBillableHours
    FROM (SELECT TimeCard.EmployeeId
    , Sum(tblTimeCardHours.BillableHours) AS SumOfBillableHours
    , tblTimeCardHours.dateWorked
    , tblTimeCardHours.workCodeId
    FROM 
    tblTimeCardHours INNER JOIN TimeCard ON
     tblTimeCardHours.TimeCardId = TimeCard.TimeCardid
    GROUP BY 
    TimeCard.EmployeeId, tblTimeCardHours.dateWorked, tblTimeCardHours.workCodeId
    HAVING 
    (((TimeCard.EmployeeId) IN (602,603)) AND
     ((tblTimeCardHours.workCodeId)In(7,10,12) AND
     tblTimeCardHours.dateWorked>#31/12/2013# ))
    )  AS [%$##@_Alias]
    GROUP BY [%$##@_Alias].EmployeeID
    ,[%$##@_Alias].WorkcodeID;
    The result of this SQL/query is:

    EmployeeID WorkcodeID SumOfSumOfBillableHours
    602 7 5
    602 10 7
    602 12 40
    603 10 5
    603 12 4

    Because of the way the foum adds this graphics, I had to put the results before the test data!! It was trying to put my text entries into the table data grids??? So read the table/data changes first to get the right sequence of events.




    I modified test data to have the following data:

    Added employeeID 603
    EmployeeId TimeCardid
    602 1
    603 2

    Added workcodeIds and hours for EmployeeID 602 and 603 to ensure here were records for
    both employees and workcodeIds including 7, 10 and 12

    TimeCardIhoursId BillableHours dateWorked workCodeId TimeCardId
    1 8 20/01/2014 12 1
    2 8 02/03/2014 12 1
    3 8 24/02/2014 12 1
    4 8 05/09/2014 12 1
    5 8 05/12/2014 12 1
    6 7 05/12/2014 10 1
    7 5 23/03/2014 7 1
    8 4 24/03/2014 12 2
    9 5 24/03/2014 10 2

  2. #17
    SalVOM is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2014
    Posts
    20
    Ok, i've added the missing select and it gave me the correct total thanks but i've still need the list of "DateWorked" to make sure i'm pulling & summing all the right dates. How do i get those back to display?

  3. #18
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,743
    Did you look at the last post I sent? It has 2 employeeids, 3 different workcodeIds, and a list of the hoursworked and worktypeId. The latest SQL was set up to give you

    Sum Hoursworked by worktypeId and EmployeeId

  4. #19
    SalVOM is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2014
    Posts
    20
    Sorry, i missed it! will try it.

  5. #20
    SalVOM is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2014
    Posts
    20
    I've entered the revised SQL and modified with the correct table names but errors with "engine can't fine table/query TimeCardHours". which is the correct name of the table!?

    SELECT [%$##@_Alias].EmployeeID
    ,[%$##@_Alias].WorkcodeID
    ,Sum([%$##@_Alias].SumOfBillableHours) AS SumOfSumOfBillableHours
    FROM
    (SELECT TimeCards.EmployeeId ,
    Sum(TimeCardHours.BillableHours) AS SumOfBillableHours ,
    TimeCardHours.dateWorked ,
    TimeCardHours.workCodeId
    FROM
    TimeCardHours INNER JOIN TimeCards ON TimeCardHours.TimeCardId = TimeCards.TimeCardid
    GROUP BY
    TimeCards.EmployeeId,
    TimeCardHours.dateWorked,
    TimeCardHours.workCodeId
    HAVING
    (((TimeCards.EmployeeId) IN (602,603)) AND
    ((TimeCardHours.workCodeId)In(7,10,12) AND TimeCardHours.dateWorked>#31/12/2013# ))
    ) AS [%$##@_Alias]
    GROUP BY [%$##@_Alias].EmployeeID
    ,[%$##@_Alias].WorkcodeID;

    Click image for larger version. 

Name:	er2.jpg 
Views:	7 
Size:	173.6 KB 
ID:	15569

  6. #21
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,743
    Your table is named Time Card Hours according to your jpg.

    So you have to put the name inside [] brackets because it has embedded spaces.[Time Card Hours]


    As mentioned in post #10
    Do yourself a major favor -adopt a naming convention that only uses A-Z0-9 and _
    You'll save yourself lots of frustration with syntax issues.

    Good luck
    Last edited by orange; 02-27-2014 at 10:00 AM. Reason: spelling

  7. #22
    amrut is offline Expert
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2012
    Location
    Dubai
    Posts
    614
    Sorry to step in.
    Access treats TimeCardHours and Time Card Hours as different tables. You screenshot shows Time Card Hours as table name and you are using TimeCardHours.

  8. #23
    SalVOM is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2014
    Posts
    20
    I appologize for the ignorance of my Access knowledge as i was trying to save myself the fustration by just using a microsoft templete and didn't change any specifications of what was built. Not knowing Access/syntax has been fustrating all in itself and I greatly do appreciate all the help.

  9. #24
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,743
    Did you get it working??
    None of us knew the pitfalls/issues with database/access when we started out. We've learned from our mistakes, assumptions and from forums and posts like this. And nobody knows it all.
    You can learn something from anyone if you're open and listen long enough.
    SQL is not a trivial subject, and Access's formatting/punctuation can be frustrating at times.

    Hang in.

  10. #25
    SalVOM is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2014
    Posts
    20
    Well I have learned alot, thanks! and the query ran this time but the results were empty, perhaps to many brackets?

    SELECT [%$##@_Alias].EmployeeID, [%$##@_Alias].WorkCodeID, Sum([%$##@_Alias].SumOfBillableHours) AS SumOfSumOfBillableHours
    FROM (SELECT [Time Cards].EmployeeID, Sum([Time Card Hours].BillableHours) AS SumOfBillableHours, [Time Card Hours].DateWorked, [Time Card Hours].WorkCodeID FROM [Time Card Hours] INNER JOIN [Time Cards] ON [Time Card Hours].TimeCardID = [Time Cards].TimeCardID GROUP BY [Time Cards].EmployeeID, [Time Card Hours].DateWorked, [Time Card Hours].WorkCodeID HAVING ((([Time Cards].EmployeeID) IN (602,603)) AND (([Time Card Hours].workCodeID)In(7,10,12) AND [Time Card Hours].DateWorked>#12/31/2013# ))) AS [%$##@_Alias]
    GROUP BY [%$##@_Alias].EmployeeID, [%$##@_Alias].WorkCodeID;

  11. #26
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,743
    The query should not run if there is a syntax error. Now if there are offsetting syntax issues it may run...

    When I copied your sql to look at it I noticed a space in TimeCard ID-- don't know if it's real or an issue with formatting on the forum

    Code:
    ..........
    FROM [Time Card Hours] INNER JOIN [Time Cards] ON
    [Time Card Hours].TimeCard ID = [Time Cards].TimeCardID 
    GROUP BY [Time Cards].EmployeeID
    , [Time Card Hours].DateWorked
    , [Time Card Hours].WorkCodeID 
    ...............................
    I'm going to adjust my mock up to match your names.........

  12. #27
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,743
    I just renamed my tables to match yours.

    I ran this SQL and it works.
    Code:
    SELECT [%$##@_Alias].EmployeeID, [%$##@_Alias].WorkcodeID, Sum([%$##@_Alias].SumOfBillableHours) AS SumOfSumOfBillableHours
    FROM (SELECT [Time Cards].EmployeeId
    , Sum([Time Card Hours].BillableHours) AS SumOfBillableHours
    , [Time Card Hours].dateWorked
    , [Time Card Hours].workCodeId 
    FROM
     [Time Card Hours] INNER JOIN [Time Cards] ON
     [Time Card Hours].TimeCardId=[Time Cards].TimeCardid 
    GROUP BY [Time Cards].EmployeeId
    , [Time Card Hours].dateWorked
    , [Time Card Hours].workCodeId 
    HAVING
     ((([Time Cards].EmployeeId) In (602,603)) And
     (([Time Card Hours].workCodeId) In (7,10,12) And
     [Time Card Hours].dateWorked>#12/31/2013#)))  AS [%$##@_Alias]
    GROUP BY [%$##@_Alias].EmployeeID
    , [%$##@_Alias].WorkcodeID;
    Results, same data as before

    EmployeeID WorkcodeID SumOfSumOfBillableHours
    602 7 5
    602 10 7
    602 12 40
    603 10 5
    603 12 4

  13. #28
    SalVOM is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2014
    Posts
    20
    looks it's the Forum because there is no space at that location.

    SELECT [%$##@_Alias].EmployeeID,
    [%$##@_Alias].WorkCodeID,
    Sum([%$##@_Alias].SumOfBillableHours) AS SumOfSumOfBillableHours
    FROM
    (SELECT [Time Cards].EmployeeID,
    Sum([Time Card Hours].BillableHours) AS SumOfBillableHours,
    [Time Card Hours].DateWorked,
    [Time Card Hours].WorkCodeID
    FROM [Time Card Hours] INNER JOIN [Time Cards] ON [Time Card Hours].TimeCardID = [Time Cards].TimeCardID
    GROUP BY [Time Cards].EmployeeID,
    [Time Card Hours].DateWorked,
    [Time Card Hours].WorkCodeID
    HAVING ((([Time Cards].EmployeeID) IN (602,603)) AND (([Time Card Hours].workCodeID)In(7,10,12) AND [Time Card Hours].DateWorked>#12/31/2013# ))) AS [%$##@_Alias]
    GROUP BY [%$##@_Alias].EmployeeID, [%$##@_Alias].WorkCodeID;



    and it runs:
    Employee ID Work Code ID SumOfSumOfBillableHours

  14. #29
    SalVOM is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2014
    Posts
    20
    Copied straight from what was sent i results were still empty.

  15. #30
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,743
    Are the field names in your tables the same as I am using?
    Can you show jpg of your table field names?

    If you want to do a copy of your database; compact and repair, and zip it I'll look at it.

    Earlier the EmployeeId and EmployeeName were a concern --Is that still an issue?

Page 2 of 3 FirstFirst 123 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 12-31-2012, 06:25 PM
  2. Replies: 3
    Last Post: 10-17-2012, 09:24 AM
  3. Replies: 3
    Last Post: 09-06-2012, 03:35 PM
  4. 'Total rows' in query
    By sk88 in forum Access
    Replies: 4
    Last Post: 08-29-2011, 09:31 AM
  5. Returning correct rows in a join/nested query
    By goneaccessing in forum Queries
    Replies: 5
    Last Post: 03-03-2010, 12:21 PM

Tags for this Thread

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