Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / General 2 / March 2007

Tip: Looking for answers? Try searching our database.

What's the best way.

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Rodney - 29 Mar 2007 17:36 GMT
I have imported some time sheet data from SAP. It has the usual information
but the Hours are recorded by Work Datewith the chrge information. I'd like
to execute a query or script to sum data by Week and display the results. I
do have a table of Week Beginning dates and Week Ending Dates.
I'd appreciate a point in the right direction.
Ken Sheridan - 29 Mar 2007 19:38 GMT
You can join the tables by week and group by the week beginning dates, then
sum the time values per week.  Just how you sum them will depend on how the
times are stored.  If they are simply the number of hours worked per day then
a simple summation will do, e.g. for the total hours per week:

SELECT [Week Beginning],
SUM([Hours Worked] AS [Total Hours]
FROM [Time Sheet], [Weeks]
WHERE [Work Date] BETWEEN
[Week Beginning] AND [Week Ending]
GROUP BY [Week Beginning];

You can of course further group the query on other column(s) to produce
subtotals per week.

If the times are recorded as start and end times per day as values of
date/time data type then you'll need to sum the result of one subtracted from
the other, and then use a function such as the following, which returns the
values in hours:minutes:seconds (and optionally days) format:

Public Function TimeDuration( _
               dtmFrom As Date, _
               dtmTo As Date, _
               Optional blnShowDays As Boolean = False) As String

   Const HOURSINDAY = 24
   Dim lngHours As Long
   Dim strMinutesSeconds As String
   Dim strDaysHours As String
   Dim dblDuration As Double
   
   dblDuration = dtmTo - dtmFrom
   
   'get number of hours
   lngHours = Int(dblDuration) * HOURSINDAY + _
       Format(dblDuration, "h")
   
   ' get minutes and seconds
   strMinutesSeconds = Format(dblDuration, ":nn:ss")
   
   If blnShowDays Then
       'get days and hours
       strDaysHours = lngHours \ HOURSINDAY & _
          " day" & IIf(lngHours \ HOURSINDAY <> 1, "s ", " ") & _
          lngHours Mod HOURSINDAY
         
       TimeDuration = strDaysHours & strMinutesSeconds
   Else
       TimeDuration = lngHours & strMinutesSeconds
   End If
   
End Function

So if the times are stored as start and end times:

SELECT [Week Beginning],
TimeDuration(SUM([StartTime]), SUM([End Time]))
AS [Total Hours]
FROM [Time Sheet], [Weeks]
WHERE [Work Date] BETWEEN
[Week Beginning] AND [Week Ending]
GROUP BY [Week Beginning];

Ken Sheridan
Stafford, England

> I have imported some time sheet data from SAP. It has the usual information
> but the Hours are recorded by Work Datewith the chrge information. I'd like
> to execute a query or script to sum data by Week and display the results. I
> do have a table of Week Beginning dates and Week Ending Dates.
> I'd appreciate a point in the right direction.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.