CREATE PROCEDURE `spAddOnlineLectureAttendence` ( IN `P_LectureId` INTEGER , IN `P_StudentId` INTEGER , IN `P_BatchId` INTEGER ) BEGIN DECLARE `V_TimeTableId` INTEGER DEFAULT ? ; IF EXISTS ( SELECT ? FROM `tonlinelecture` WHERE `id` = `P_LectureId` AND `BatchId` = `P_BatchId` ) THEN IF EXISTS ( SELECT ? FROM `tonlinelearningstudentattendance` WHERE `OnlineLectureId` = `P_LectureId` AND `StudentId` = `P_StudentId` ) THEN UPDATE `vida_lms` . `tonlinelearningstudentattendance` SET `LastOutDateTime` = NOW ( ) , `UpdatedUserId` = `P_StudentId` , `UpdatedDateTime` = NOW ( ) WHERE `OnlineLectureId` = `P_LectureId` AND `StudentId` = `P_StudentId` ; SELECT ? ; ELSE SET `V_TimeTableId` = ( SELECT DISTINCTROW `TimeTableId` FROM `tonlinelecture` WHERE `id` = `P_LectureId` AND `BatchId` = `P_BatchId` ) ; INSERT INTO `vida_lms` . `tonlinelearningstudentattendance` ( `OnlineLectureId` , `StudentId` , `FirstInDateTime` , `IsPresent` , `CreatedDateTime` , `CreatedUserId` , `AttendanceDate` , `TimeTableId` ) VALUES ( `P_LectureId` , `P_StudentId` , NOW ( ) , ? , NOW ( ) , `P_StudentId` , NOW ( ) , `V_TimeTableId` ) ; SELECT ? ; END IF ; ELSE SELECT ? ; END IF ; END 