CREATE PROCEDURE `spAddEtestEvalute` ( IN `P_TestId` INTEGER , IN `P_StudentId` INTEGER , IN `P_AnswerId` INTEGER , IN `P_Marks` DECIMAL (...) , IN `P_Remarks` LONGTEXT , IN `P_TeacherEvaluatedFilePath` LONGTEXT ) BEGIN DECLARE `V_ObtainMarks` DECIMAL (...) DEFAULT ? ; UPDATE `teteststudentanswer` SET `ScoredMarks` = `P_Marks` , `TeacherEvaluatedFilePath` = `P_TeacherEvaluatedFilePath` , `Remark` = `P_Remarks` WHERE `Id` = `P_AnswerId` AND `TestId` = `P_TestId` AND `StudentId` = `P_StudentId` ; SET `V_ObtainMarks` = ( SELECT SUM ( `ScoredMarks` ) FROM `teteststudentanswer` WHERE `TestId` = `P_TestId` AND `StudentId` = `P_StudentId` ) ; UPDATE `tresult` SET `ObtainMarks` = `V_ObtainMarks` WHERE `TestId` = `P_TestId` AND `StudentId` = `P_StudentId` ; IF NOT EXISTS ( SELECT ? FROM `teteststudentanswer` WHERE `TestId` = `P_TestId` AND `StudentId` = `P_StudentId` AND `ScoredMarks` IS NULL ) THEN UPDATE `tresult` SET `IsGenerated` = ? WHERE `TestId` = `P_TestId` AND `StudentId` = `P_StudentId` ; END IF ; SELECT ? ; END 