Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

How to query sql in MS Access 2007 Find Min & Max with DateTime? Expand / Collapse
Author
Message
Posted Tuesday, April 23, 2013 9:10 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Monday, April 29, 2013 9:44 AM
Points: 14, Visits: 46
i query sql in MS Access 2007.i want find mix and max function with datetime.

This Code:

SELECT inf.SSN AS EmpNo, ck.CHECKTIME AS CHKDATE,Min(ck.CHECKTIME) AS TIMEIN, Max(ck.CHECKTIME) AS TIMEOUT
FROM CHECKINOUT ck INNER JOIN USERINFO inf ON ck.Badgenumber = inf.Badgenumber
WHERE (((ck.CHECKTIME)>=#20/03/2013#)
Group By inf.SSN, ck.CHECKTIME
ORDER BY inf.SSN, ck.CHECKTIME

Result:

EmpNo | CHKDATE | TIMEIN | TIMEOUT
1290005 | 20/3/2556 7:24:52 | 20/3/2556 7:24:52 | 20/3/2556 7:24:52
1290005 | 20/3/2556 19:07:54 | 20/3/2556 19:07:54 | 20/3/2556 19:07:54
1290005 | 21/3/2556 7:14:29 | 21/3/2556 7:14:29 | 21/3/2556 7:14:29
1320004 | 20/3/2556 7:28:57 | 20/3/2556 7:28:57 | 20/3/2556 7:28:57
1320004 | 20/3/2556 17:05:23 | 20/3/2556 17:05:23 | 20/3/2556 17:05:23
1320004 | 21/3/2556 7:15:30 | 21/3/2556 7:15:30 | 21/3/2556 7:15:30


But I want Result:

EmpNo | CHKDATE | TIMEIN | TIMEOUT
1290005 | 20/3/2556 00:00:00 | 20/3/2556 7:24:52 | 20/3/2556 19:07:54
1290005 | 21/3/2556 00:00:00 | 21/3/2556 7:14:29 | 21/3/2556 7:14:29
1320004 | 20/3/2556 00:00:00 | 20/3/2556 7:28:57 | 20/3/2556 17:05:23
1320004 | 21/3/2556 00:00:00 | 21/3/2556 7:15:30 | 21/3/2556 7:15:30


How query this result in Access 2007. Thanks For your Time. ;)
Post #1445509
Posted Tuesday, April 23, 2013 4:29 PM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: 2 days ago @ 8:52 AM
Points: 142, Visits: 518
In order to solve this sort of problem using Group By queries, you need to use multiple queries. The Max function is simply taking the Max function of the record where the Min was found, and that's because the Min only has one record, the minimum (which is the CheckIn record). The problem is often solved by using ADO or DAO record processing from VBA, and simply stepping through the records. One complication that has to be dealt with in either case is where there is a checkin record but no checkout record. It shouldn't happen, but it invariably will at some point.

Wendell


Wendell
Colorful Colorado
You can't see the view if you don't climb the mountain!
Post #1445713
Posted Thursday, May 16, 2013 2:38 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Friday, August 15, 2014 2:26 AM
Points: 188, Visits: 773
You need to group by just the date portion of CHECKTIME - try this or similar

SELECT inf.SSN AS EmpNo, Format(ck.CHECKTIME, "dd/mm/yyyy") AS CHKDATE,Min(ck.CHECKTIME) AS TIMEIN, Max(ck.CHECKTIME) AS TIMEOUT
FROM CHECKINOUT ck INNER JOIN USERINFO inf ON ck.Badgenumber = inf.Badgenumber
WHERE (((ck.CHECKTIME)>=#20/03/2013#)
Group By inf.SSN, format(ck.CHECKTIME, "yyyymmdd")
ORDER BY inf.SSN, format(ck.CHECKTIME, "yyyymmdd")

Post #1453369
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse