CREATE PROCEDURE `spCreateHomeWork` ( IN `P_StudentIds` LONGTEXT , IN `P_TeacherId` INTEGER , IN `P_BatchId` INTEGER , IN `P_StatusId` INTEGER , IN `P_Title` VARCHARACTER (?) , IN `P_Notes` VARCHARACTER (?) , IN `P_SubmissionDateTime` DATETIME , IN `P_IsSendNotificationHomeworkNotSubmit` BIT , IN `P_IsSendSMSHomeworkNotSubmit` BIT ) BEGIN DECLARE `P_HomeWorkId` INTEGER DEFAULT ? ; DECLARE `P_Values` VARCHARACTER (?) DEFAULT ? ; DECLARE `P_Insert` VARCHARACTER (?) DEFAULT ? ; IF EXISTS ( SELECT ? FROM `tstudent` , `tteacher` , `tbatch` WHERE `tbatch` . `Id` = `P_BatchId` AND `tteacher` . `Id` = `P_TeacherId` AND `FIND_IN_SET` ( `tstudent` . `Id` , `P_StudentIds` ) ) THEN START TRANSACTION ; BEGIN INSERT INTO `thomework` ( `StudentId` , `TeacherId` , `BatchId` , `Title` , `Note` , `HomeWorkDateTime` , `CreatedDateTime` , `UpdatedDateTime` , `IsSendNotificationHomeworkNotSubmit` , `IsSendSMSHomeworkNotSubmit` ) VALUES ( `P_StudentIds` , `P_TeacherId` , `P_BatchId` , `P_Title` , `P_Notes` , `P_SubmissionDateTime` , NOW ( ) , NOW ( ) , `P_IsSendNotificationHomeworkNotSubmit` , `P_IsSendSMSHomeworkNotSubmit` ) ; SET `P_HomeWorkId` = `LAST_INSERT_ID` ( ) ; SET `P_Values` = REPLACE ( 