CREATE PROCEDURE `spAlertLogAdd` ( IN `P_AlertXML` LONGTEXT , IN `P_InstituteId` INTEGER ) BEGIN DECLARE `AL_Count` INTEGER DEFAULT ? ; DECLARE `i` INTEGER DEFAULT ? ; DECLARE `FromId` INTEGER DEFAULT ? ; DECLARE `ToId` INTEGER DEFAULT ? ; DECLARE `InstituteIdVar` INTEGER DEFAULT ? ; SET `FromId` = ( SELECT MAX ( `Id` ) FROM `vida_lms` . `talertlog` ) + ? ; SET `AL_Count` = `ExtractValue` ( `P_AlertXML` , ? ) ; WHILE `i` <= `AL_Count` DO IF ( `ExtractValue` ( `P_AlertXML` , `CONCAT` ( ? , `i` , ? ) ) = ? ) THEN SET `InstituteIdVar` = ( SELECT `InstituteId` FROM `tstudent` WHERE `Id` = `ExtractValue` ( `P_AlertXML` , `CONCAT` ( ? , `i` , ? ) ) ) ; ELSE SET `InstituteIdVar` = ( SELECT `InstituteId` FROM `tTeacher` WHERE `Id` = `ExtractValue` ( `P_AlertXML` , `CONCAT` ( ? , `i` , ? ) ) ) ; END IF ; INSERT INTO `vida_lms` . `talertlog` ( `ContactId` , `AlertMessage` , `AlertSubject` , `EventId` , `CreatedUserId` , `CreatedDateTime` , `AlertModeId` , `InstituteId` , `ReceiverRoleTypeId` , `ReceiverSourceId` ) VALUES ( `ExtractValue` ( `P_AlertXML` , `CONCAT` ( ? , `i` , ? ) ) , `ExtractValue` ( `P_AlertXML` , `CONCAT` ( ? , `i` , ? ) ) , 