crystalnewbie
MIS
I have a table that looks like this:
EmpID---EventDate---InpunchDTM---OutpunchDTM---StartReason
1000---1/1/04---9:00am---12:00pm---NewShift
1000---1/1/04---12:30pm---5:30pm---MealBreak
1002---1/1/04---9:00am---12:30pm---NewShift
1002---1/1/04---12:50pm---5:30pm---MealBreak
1002---1/1/04---9:00am---5:00pm---NewShift
What I'm trying to calculate is the amount of break they took, so for the example above, EmpID = 1000 took a 30 min break.
I tried writing a corelated subquery to rewrite the table to look like below so that I can do a datediff on the OutpunchDTM and BreakEnd to get their break time. However, i'm getting an error stating that the subquery is returning more than 1 value.
EmpID---EventDate---InpunchDTM---OutpunchDTM---StartReason---BreakEnd
1000---1/1/04---9:00am---12:00pm---NewShift---12:30pm
My sql is as follows:
select empid, eventdate, inpunchdtm, outpunchdtm, startreason,
(select Inpunchdtm from mytable as B where B.empid = mytable.empid and startreason = 'MealBreak') -- also tried using max() on inpuchdtm but it's giving the wrong date
from
mytable
where
startreason = 'NewShift'
Would like to solve this without using a stored procedure.
Any help or a different approach to solving my problem is greatly appreciated. Thanks.
EmpID---EventDate---InpunchDTM---OutpunchDTM---StartReason
1000---1/1/04---9:00am---12:00pm---NewShift
1000---1/1/04---12:30pm---5:30pm---MealBreak
1002---1/1/04---9:00am---12:30pm---NewShift
1002---1/1/04---12:50pm---5:30pm---MealBreak
1002---1/1/04---9:00am---5:00pm---NewShift
What I'm trying to calculate is the amount of break they took, so for the example above, EmpID = 1000 took a 30 min break.
I tried writing a corelated subquery to rewrite the table to look like below so that I can do a datediff on the OutpunchDTM and BreakEnd to get their break time. However, i'm getting an error stating that the subquery is returning more than 1 value.
EmpID---EventDate---InpunchDTM---OutpunchDTM---StartReason---BreakEnd
1000---1/1/04---9:00am---12:00pm---NewShift---12:30pm
My sql is as follows:
select empid, eventdate, inpunchdtm, outpunchdtm, startreason,
(select Inpunchdtm from mytable as B where B.empid = mytable.empid and startreason = 'MealBreak') -- also tried using max() on inpuchdtm but it's giving the wrong date
from
mytable
where
startreason = 'NewShift'
Would like to solve this without using a stored procedure.
Any help or a different approach to solving my problem is greatly appreciated. Thanks.