Doable, yes. .
Assuming the dateStamp contains and the date and the time (of the IO)
Assuming field IO contains "I" or "O" (for in or for out)
kind of:
employee dateStamp IO
john 2001.01.01 09:00:06 i
john 2001.01.01 11:58:12 o
john 2001.01.01 12:49:16 i
john 2001.01.01 17:02:08 o
Rank the data by employee, by IO, by date, accordingly to the time, which
can be done with the following query:
----------------------
SELECT a.employee,
DateValue(a.dateStamp) AS theDate,
TimeValue(a.dateStamp) AS theTime,
a.io,
COUNT(*) AS rank
FROM tableName AS a INNER JOIN tableName AS b
ON a.employee=b.employee
AND a.io = b.io
AND DateValue(a.dateStamp) = DateValue(b.dateStamp)
AND a.dateStamp >= b.dateStamp
GROUP BY a.employee,
DateValue(a.dateStamp),
TimeValue(a.dateStamp),
a.io
-------------------------
Save it under the name, say, qr1. Then, make the crosstab:
-------------------------
TRANSFORM LAST(theTime)
SELECT employee, theDate
FROM qr1
GROUP BY employee, theDate
PIVOT io & rank IN ("i1", "o1", "i2", "o2", ... , "i8", "o8")
-------------------------
should produce something like:
employee theDate i1 o1 i2 o2
... i8 o8
john 2001.01.01 09:00:06 11:58:12 12:49:16 17:02:08 ... null
null
Hoping it may help,
Vanderghast, Access MVP
>I have a two tables that look like:
> Emp table Punch table
[quoted text clipped - 39 lines]
> George Applegate
> gappleg8@nospam.fmctc
George Applegate - 29 May 2008 21:34 GMT
Michel,
Thanks a ton for your help! You have me close, I think. The qr1
query puts out the data as you indicated
emp# date time IO rank
2000 01/01/08 11:30 IN 1
2000 01/01/08 14:40 OUT 1
2000 01/01/08 15:30 IN 2
But when I do the Crosstab, I am not getting any times to actually
show.
The Cross tab has
2000 01/01/08 blanks blanks blanks blanks, blanks
2000 01/02/08 blanks blanks blanks blanks blanks
I don't know if something is wrong with the PIVOT statement? It shows
the headings but no times in them. Otherwise it seems to be working
as advertised.
One note - the field for InOut is "InOut" and second, the value in
there is IN or OUT
I made the Pivot statement:
PIVOT InOut & rank IN("IN1", "OUT1", "IN2", "OUT2", "IN3"...
Any ideas what I did wrong? The headings are there, just no times
showing. Or is it something with my Transform statement
I am just using the field which is Logtime and it seems to be in qry1
okay. Qry1 looks exactly right. It seems to be more of a problem
with my PIVOT statement??
I get the employee # and the Log date in the crosstab query, just no
times...
Any ideas or suggestions??
By the way, THANKS A MILLION FOR YOUR HELP!!!
ga
>Doable, yes. .
>
[quoted text clipped - 94 lines]
>> George Applegate
>> gappleg8@nospam.fmctc
George Applegate
gappleg8@nospam.fmctc
Michel Walsh - 30 May 2008 14:26 GMT
Try the crosstab without the IN list in the PIVOT:
TRANSFORM LAST(theTime)
SELECT employee, theDate
FROM qr1
GROUP BY employee, theDate
PIVOT io & rank
That MAY creates more than 8 in or 8 out column, but you can fix that later.
Be sure to take note ot the fields name created. They must be typed exactly
as they are created, if we use the IN( ) list of the PIVOT clause (as
string, ie, delimited by double quotes).
Vanderghast, Access MVP
> Michel,
>
[quoted text clipped - 35 lines]
>
> Any ideas or suggestions??
George Applegate - 30 May 2008 14:58 GMT
Michel,
THANKS A TON! That did the trick. I think the problem is, I would
have to put it as "IN 1" and "OUT 1", etc. The rank is
apparently too many characters. But just doing it this way works
great!
Thanks much for all of your help. You take something extremely
complicated and make it look like a piece of cake!
ga
>Try the crosstab without the IN list in the PIVOT:
>
[quoted text clipped - 50 lines]
>>
>> Any ideas or suggestions??
George Applegate
gappleg8@nospam.fmctc
Michel Walsh - 30 May 2008 15:06 GMT
You can use the VBA function TRIM to remove trailing spaces, before making
the concatenation to rank :
TRANSFORM ...
PIVOT TRIM(io) & rank
Vanderghast, Access MVP
> Michel,
>
[quoted text clipped - 67 lines]
> George Applegate
> gappleg8@nospam.fmctc
George Applegate - 29 May 2008 21:38 GMT
One other thing.
The employee name comes from a different table...how do I tie that in?
Do I connect that in the crosstab query or in the original query, if I
want that to show. link is on employee #
Can I do that???
thanks,
ga
>Doable, yes. .
>
[quoted text clipped - 94 lines]
>> George Applegate
>> gappleg8@nospam.fmctc
George Applegate
gappleg8@nospam.fmctc
Michel Walsh - 30 May 2008 14:27 GMT
You can make another query: bring the crosstab and the table that will
supply the name instead of the id number, and join them on their common
id_number fields.
Vanderghast, Access MVP
> One other thing.
>
[quoted text clipped - 5 lines]
> thanks,
> ga
.fmctc