Results 1 to 7 of 7
  1. #1
    sdel_nevo is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2013
    Location
    Gloucester, UK
    Posts
    402

    Struggling with working hours query

    Hi Guys



    With help from the community on this site I have been using this query with to work out our response times by issues for our help desk support database.

    SELECT Count(AssetNotes.AssetNotesID) AS CountOfAssetNotesID, AssetNotesType.NoteType, AssetNotesType.ID, NZ(Sum(DateDiff("n",[issueOpenedTime],[NoteEndtime])),0) AS [Actual Time]
    FROM AssetNotesType RIGHT JOIN AssetNotes ON AssetNotesType.ID = AssetNotes.NotesType
    WHERE (((AssetNotes.IssueClosed) Between [forms].[ResponceTimeDates].[startdate] And [forms].[ResponceTimeDates].[enddate]))
    GROUP BY AssetNotesType.NoteType, AssetNotesType.ID
    HAVING (((AssetNotesType.NoteType) Not Like "General Note") AND ((NZ(Sum(DateDiff("n",[issueOpenedTime],[NoteEndtime])),0)) Is Not Null));

    the above query calculates the minutes [Actual Time] between the start and finish times this is working really well.

    what I am having trouble with and to be honest totally confused by is how to calculate the time it has taken during working hours Monday - Friday 9am to 5pm.

    any help with this would be fantastic

    many thanks in advance

    Steve

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    Start with a query say qsWorkTime, that takes the current date/time and re-sets the time to the Workday range:

    iif ([issueOpenedTime]> #9:00 am#,issueOpenedTime,#9:00 am#) as StartTime
    iif ([NoteEndtime]< #5:00 Pm#,NoteEndtime,#5:00 Pm#) as EndTime


    THEN use your query above on this qry qsWorkTime that only shows the time between 9-5.

  3. #3
    sdel_nevo is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2013
    Location
    Gloucester, UK
    Posts
    402
    Hi ranman256

    the above you sent looks great, but how would I do that? do I create a totally new query? based on the one above or create a new query and reference this into the above query.

    what would I then have to do to remove the time the ticket was open over the weekend?

    if I opened a ticket on Friday at 9am and closed it Monday morning at 11am I need to get 10 as the hours run
    8 hours for Friday and 2 hours on Monday total hours 10

    this is above my understanding of access but this website is fantastic for learning,

    many thanks again for your help

    Steve

  4. #4
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    I see the complication...wow

    Before you start, You'd have to run a 'fix' on the time table, If start and end time cross over the weekend.
    I would say a UNION query.
    Q1 would do the fix I gave above, but include same day cutoffs.

    iif ([issueOpenedTime]> format([issueOpenedTime],"mm/dd/yy") & " 9:00 am",[issueOpenedTime],format([issueOpenedTime],"mm/dd/yy") & " 9:00 am") as StartTime
    iif ([NoteEndtime]< format([NoteEndtime],"mm/dd/yy") & " 5:00 Pm",[NoteEndtime]< format([NoteEndtime],"mm/dd/yy") & " 5:00 Pm") as EndTime

    Q2 would have to fix the cross day cutoffs (like new records)
    select [id], (format([NoteEndtime],"mm/dd/yy") & " 9:00 am") , [NoteEndtime]
    where format([issueOpenedTime],"mm/dd/yy") < (format([NoteEndtime],"mm/dd/yy")

    Q3 would be the union of 1 & 2
    select * from Q1
    union
    select * from Q2

    Now you have all records for each day broken up in business days to run your query against Q3.

  5. #5
    sdel_nevo is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2013
    Location
    Gloucester, UK
    Posts
    402
    Hi

    thanks for getting back

    yes q1 includes same day cutoff so that's good

    thanks for the heads up I will try q2 and q3 and let you know how I get on

    many thanks

    Steve

  6. #6
    recyan's Avatar
    recyan is offline Expert
    Windows 2K Access 2000
    Join Date
    Dec 2011
    Posts
    662
    Whenever free, try & go thro the discussion in below thread ( May be or May not be relevant to you):

    http://forums.aspfree.com/microsoft-...ys-379275.html

    Thanks

  7. #7
    sdel_nevo is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2013
    Location
    Gloucester, UK
    Posts
    402
    Hi recyan

    I will take a look at that, many thanks
    Steve

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

Similar Threads

  1. Struggling with this query
    By ramangill in forum Queries
    Replies: 8
    Last Post: 04-10-2014, 09:14 PM
  2. Replies: 14
    Last Post: 09-11-2013, 01:10 PM
  3. Replies: 1
    Last Post: 08-08-2012, 01:42 PM
  4. Replies: 4
    Last Post: 08-06-2012, 10:25 AM
  5. struggling with query, plz help
    By jimgros in forum Queries
    Replies: 2
    Last Post: 07-26-2011, 03:35 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