Hi ,
i'm doing a project which invovles time and attendance management. When i download datas from the biometric reader , i got the records in the following format,
empCode date time
5001 12/09/2011 09:05:34
5002 12/09/2011 09:33:13
5001 12/09/2011 13:05:53
5002 12/09/2011 13:22:24
5001 12/09/2011 14:05:22
5002 12/09/2011 14:33:53
5001 12/09/2011 18:05:09
5002 12/09/2011 17:44:34
i want to show the above records as follows ,
(the intime , break_out , break_in and outtime are based on 'time')
empCode date intime break_out break_in outtime
5001 12/09/2011 09:05:34 13:05:53 14:05:22 18:05:09
5002 12/09/2011 09:33:13 13:22:24 14:33:53 17:44:34
so i tried the following query but it didnt work,
SELECT a.emp_Code, a.dates, a.times AS intime, b.break_out , c.break_in , d.outtime
FROM punch_details AS a LEFT OUTER JOIN
(((SELECT emp_code, dates, times AS break_out
FROM punch_details
WHERE (times > '13:00:00') and (times < '13:30:00')) AS b LEFT OUTER JOIN
(SELECT emp_code, dates, times AS break_in
FROM punch_details
WHERE (times > '13:30:00') and (times < '14:30:00')) AS c on b.emp_code=c.emp_code and b.dates = a.dates)
LEFT OUTER JOIN
(SELECT emp_code, dates, times AS outtime
FROM punch_details
WHERE (times > '17:00:00')) AS d on c.emp_code=d.emp_code and c.dates = d.dates) ON A.emp_code = b.emp_code AND A.dates = b.dates
WHERE (A.times > '09:00:00') and (A.times < '13:00:00')
How do i do?..
Loading
Pravin MorePosted Sep 20, 2011, 7:44 AM
here is solution for your problem...i created same table on my machin and inserted same values posted by you n written query .its working fine upto your requirment..........
here is my query........
select distinct a.empcode,a.date,(select aa.time as Intime from punch_details aa where time between '09:05:34.0000000' and '13:00:00.0000000' and aa.empcode=a.empcode ) as IN_time,
(select aa.time as break_out from punch_details aa where time between '13:00:00' and '13:30:00' and aa.empcode=a.empcode ) as break_out,
(select aa.time as break_in from punch_details aa where time between '13:30:00' and '15:00:00' and aa.empcode=a.empcode ) as break_in,
(select aa.time as outtime from punch_details aa where time > '17:00:00' and aa.empcode=a.empcode ) as outtime from (select * from punch_details ) as au can change column name and time condition according to you......
it will definatly solve your problem.
Thank you,
Pravin.
warat mookdaananPosted Jul 4, 2012, 10:40 PM
i copy your sample sql and test my sql it work great but when i want select only person id and choose date between 01/01/2012 to 31/01/2012 i can,t do that
select distinct a.emid,a.datest,(select MIN(aa.timest) as Intime from time aa where timest between '06:00:00' and '14:00:00' and aa.emid=a.emid ) as timein, (select MIN(aa.timest) as outtime from time aa where timest > '16:30:00' and aa.emid=a.emid ) as timeout from (select * from time ) as a
please tell me
thank you
Arunkumar EmmPosted Sep 21, 2011, 2:13 AM
OMG. That's what i'm looking for. Thanks alot pravin..