INSERT INTO attendance_process (empid,DATE,time_in,time_out, late_time,early_time, STATUS,total_hours) SELECT empid, DATE , clock_in, clock_out , late, early, CASE WHEN (absent = 'true') THEN 6 WHEN (TIME_TO_SEC(clock_in)>0 AND TIME_TO_SEC(clock_out)=0) THEN 4 WHEN (TIME_TO_SEC(clock_in)=0 AND TIME_TO_SEC(clock_out)>0) THEN 4 WHEN (TIME_TO_SEC(early) > 0) THEN 3 WHEN (TIME_TO_SEC(late) > 0 ) THEN 2 ELSE 1 END AS STATUS, time_spent FROM attendance