SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


How to query sql in MS Access 2007 Find Min & Max with DateTime?


How to query sql in MS Access 2007 Find Min & Max with DateTime?

Author
Message
ppc493
ppc493
Grasshopper
Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)

Group: General Forum Members
Points: 14 Visits: 47
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. Wink
WendellB
WendellB
Right there with Babe
Right there with Babe (735 reputation)Right there with Babe (735 reputation)Right there with Babe (735 reputation)Right there with Babe (735 reputation)Right there with Babe (735 reputation)Right there with Babe (735 reputation)Right there with Babe (735 reputation)Right there with Babe (735 reputation)

Group: General Forum Members
Points: 735 Visits: 1751
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!
Chris Quinn-821458
Chris Quinn-821458
Old Hand
Old Hand (324 reputation)Old Hand (324 reputation)Old Hand (324 reputation)Old Hand (324 reputation)Old Hand (324 reputation)Old Hand (324 reputation)Old Hand (324 reputation)Old Hand (324 reputation)

Group: General Forum Members
Points: 324 Visits: 841
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")


Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search