Link to home
Get AccessLog in
Avatar of Roman F
Roman FFlag for United States of America

asked on

need your help with access query

i have a table Data and i am using query Query 1
Name
InspectorName      InsDate               Time
User1                      5/1/2015      00:05
User1                      5/1/2015      00:05
User1                      5/1/2015      00:15
User1                      5/1/2015      02:10
User1                      5/1/2015      00:35
User1                      5/1/2015      01:40
User1                      5/1/2015      00:10
User1                      5/1/2015      00:35
User1                      5/1/2015      00:50
User1                     5/1/2015              00:25
User1                     5/1/2015              00:20
User1                     5/1/2015              00:35
User1                     5/1/2015              00:15
User1                     5/1/2015              00:10
what i need to calculate the total sum of the TIme, in this case it should be 8 hours 10 minutes

something needs to be converted to the right format, since i canot apply the sum to my Time
Avatar of omgang
omgang
Flag of United States of America image

SELECT tblInspector.InspectorName, tblInspector.InsDate, Sum(DatePart("n",[InsTime])) AS TotalTime
FROM tblInspector
GROUP BY tblInspector.InspectorName, tblInspector.InsDate;


Use the DatePart function.  See example above.

OM Gang
Avatar of Roman F

ASKER

thank you for your respond

i am having an error when i run the query
SELECT data.InspectorName, data.InsDate, sum(DatePart("n",[duration])
FROM data
group by InspectorName, InsDate
What error are you receiving?  Is [duration] column a date/time data type?  The DatePart function works on date/time data types only.
OM Gang
Avatar of Roman F

ASKER

you have a database attached, could you look at the database,
I don't see it.
Avatar of Roman F

ASKER

Sorry :)
Test.accdb
Try:

SELECT InspectorName      , Sum([Time]*24) AS sumOfTime
FROM Data
GROUP BY InspectorName ;

Open in new window

I am receiving no error with your sample database.

Query
SELECT data.InspectorName, data.InsDate, Sum(DatePart("n",[duration])) AS TotalTime
FROM data
GROUP BY data.InspectorName, data.InsDate;

Results
InspectorName      InsDate      TotalTime
User1      5/1/2015      310
User1      5/4/2015      0
User2      5/1/2015      446
User2      5/4/2015      0

OM Gang
Avatar of Roman F

ASKER

yep, so far is great,
let me check something
Applied my comment to your database.
attached.

SELECT data.InspectorName, Sum([duration]*24) AS Expr1
FROM data
GROUP BY data.InspectorName;

Open in new window


Result:
InspectorName      Expr1
User1              16.1666666666667
User2               18.4333333333333
Test-1.accdb
Avatar of Roman F

ASKER

great, and finally, how to round 8.166666666666666666666 to 8:10???
0:05
0:15
0:35
0:20
0:25
0:50
0:35
0:10
0:05
1:40
0:10
0:35
2:10
0:15
yourValue = 8.166666666666666666666

Format(8.16666666666, "h:nn:ss")
You should not multiply by 24 but go straight:

SELECT InspectorName, Sum([duration]) AS SumotTime
FROM data
GROUP BY InspectorName;

Then apply the format h:nn to SumOfTime.

/gustav
Avatar of Roman F

ASKER

none of your last comments are work for you, sorry
SOLUTION
Avatar of Hamed Nasr
Hamed Nasr
Flag of Oman image

Link to home
membership
This content is only available to members.
To access this content, you must be a member of Experts Exchange.
Get Access
SOLUTION
Link to home
membership
This content is only available to members.
To access this content, you must be a member of Experts Exchange.
Get Access
SOLUTION
Link to home
membership
This content is only available to members.
To access this content, you must be a member of Experts Exchange.
Get Access
ASKER CERTIFIED SOLUTION
Link to home
membership
This content is only available to members.
To access this content, you must be a member of Experts Exchange.
Get Access
Avatar of Roman F

ASKER

Thank you