CREATE PROCEDURE `spUpdateHomeWork` ( IN `P_StudentIds` LONGTEXT , IN `P_HomeWorkId` INTEGER , IN `P_Title` VARCHARACTER (?) , IN `P_Notes` VARCHARACTER (?) , IN `P_SubmissionDateTime` DATETIME , IN `P_StatusId` INTEGER , IN `P_IsSendNotificationHomeworkNotSubmit` BIT , IN `P_IsSendSMSHomeworkNotSubmit` BIT ) BEGIN DECLARE `P_BatchId` INTEGER ; DECLARE `P_Values` VARCHARACTER (?) DEFAULT ? ; DECLARE `P_Insert` VARCHARACTER (?) DEFAULT ? ; IF EXISTS ( SELECT ? FROM `thomework` WHERE `Id` = `P_HomeWorkId` ) THEN DELETE FROM `thomeworkassign` WHERE `HomeWorkId` = `P_HomeWorkId` ; UPDATE `thomework` SET `StudentId` = `P_StudentIds` , `Title` = `P_Title` , `Note` = `P_Notes` , `HomeworkDateTime` = `P_SubmissionDateTime` , `IsSendNotificationHomeworkNotSubmit` = `IsSendNotificationHomeworkNotSubmit` , `IsSendSMSHomeworkNotSubmit` = `IsSendSMSHomeworkNotSubmit` , `UpdatedDateTime` = NOW ( ) WHERE `thomework` . `Id` = `P_HomeWorkId` ; SET `P_BatchId` = ( SELECT `BatchId` FROM `thomework` WHERE `Id` = `P_HomeWorkId` ) ; SET `P_Values` = REPLACE ( `P_StudentIds` , ? , `CONCAT` ( ? , `P_HomeworkId` , ? , `P_StatusId` , ? ) ) ; SET `P_Values` = `CONCAT` ( ? , `P_Values` , ? , 