Hi,
SELECT a.empNo, a.dateTime As LogIn, b.dateTime As LogOut
FROM (myTable As a LEFT JOIN myTable As b
ON a.empNo=b.empNo AND a.dateTime <= b.dateTime)
LEFT JOIN myTable As c
ON a.empNo=c.empNo AND a.dateTime <=c.dateTime
WHERE a.InOut = "in" AND (b.InOut="Out" OR b.InOut Is NULL)
AND (c.InOut = "Out" OR c.InOut Is
NULL)
GROUP BY a.empNo, a.dateTime, b.dateTime
HAVING Nz(b.dateTime,0) = Nz(MIN(c.dateTime), 0)
Should do. If you are only interested in completed 'transactions' ( those
that have and a in and a out), you can simplify a little bit:
SELECT a.empNo, a.dateTime As LogIn, b.dateTime As LogOut
FROM (myTable As a INNER JOIN myTable As b
ON a.empNo=b.empNo AND a.dateTime <= b.dateTime)
INNER JOIN myTable As c
ON a.empNo=c.empNo AND a.dateTime <=c.dateTime
WHERE a.InOut = "in" AND b.InOut="Out"
AND c.InOut = "Out"
GROUP BY a.empNo, a.dateTime, b.dateTime
HAVING b.dateTime = MIN(c.dateTime)
I also assume your dateTime is in ONE field, it is, isn't it? If not, it is
much more verbose. As example, when you compare 3' 11" with 3' 8", it is
harder than if you compare 47" with 44", in the last case, it is just ONE
test, in the first case, it is:
feetA > feetB OR ( feetA=feetB AND inchesA >= inchesB)
much, much less elegant than
totalInchesA >= totalInchesB
Same for date, and time.
Hoping it may help,
Vanderghast, Access MVP
> Hi,
> I have a table:
[quoted text clipped - 19 lines]
>
> realspido