We're stuck of this function on how to get the total hours of time column, what we want is, the duty off minus the time of duty on from morning time, as well as the afternoon time so that we can sum the hours of the time column. Dutyon and DutyOff are not column names, so we're having a hard time. Can you pleaaaaase help us. And we want to display the total to the last row of time column. Thanks.How to get the time difference from dutyoff to dutyon of AM
We're stuck of this function on how to get the total hours of time column, what we want is, the duty off minus the time of duty on from morning time, as well as the afternoon time so that we can sum the hours of the time column. Dutyon and DutyOff are not column names, so we're having a hard time. Can you pleaaaaase help us. And we want to display the total to the last row of time column. Thanks.2 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Former memberPosted Jan 28, 2016, 6:15 AM EST
) INSERT INTO #temptable (WorkersId,InandOut,dateandTime) VALUES (111111113,'DutyOn','2016-01-20 08:00:00') INSERT INTO #temptable (WorkersId,InandOut,dateandTime) VALUES (111111113,'DutyOff','2016-01-20 12:00:00') INSERT INTO #temptable (WorkersId,InandOut,dateandTime) VALUES (111111113,'DutyOn','2016-01-20 13:00:00') INSERT INTO #temptable (WorkersId,InandOut,dateandTime) VALUES (111111113,'DutyOff','2016-01-20 17:00:00') ;WITH cte AS ( --Data Setup SELECT WorkersId, inandout, dateandtime,TimestampRanking, CASE WHEN inandout = 'DutyOn' THEN 1 ELSE 2 END AS Punch FROM ( SELECT WorkersId, inandout, dateandtime, RANK() OVER(PARTITION BY WorkersId ORDER BY dateandTime) AS TimestampRanking FROM #temptableRalph Sacro3 pointsPosted Jan 29, 2016, 5:31 AM EST