CREATE PROCEDURE `spAddContentAssign` ( IN `P_ContentPath` VARCHARACTER (?) , IN `P_ContentTitle` VARCHARACTER (?) , IN `P_ContentLink` VARCHARACTER (?) , IN `P_ContentTypeId` INTEGER , IN `P_ContentId` INTEGER , IN `P_Duration` VARCHARACTER (?) , IN `P_BatchId` INTEGER , IN `P_Remark` VARCHARACTER (?) ) BEGIN IF EXISTS ( SELECT ? FROM `tteachercontent` WHERE `Id` = `P_ContentId` ) THEN IF `P_ContentTypeId` = ? THEN START TRANSACTION ; IF NOT EXISTS ( SELECT ? FROM `tteachercontentassign` WHERE `TeacherContentId` = `P_ContentId` AND `BatchId` = `P_BatchId` ) THEN IF EXISTS ( SELECT ? FROM `tteachercontent` WHERE `id` = `P_ContentId` AND `ContentTypeId` = ? ) THEN INSERT INTO `tteachercontentassign` ( `TeacherContentId` , `BatchId` , `ContentPath` , `ContentTitle` , `ContentTypeId` , `CreatedDateTime` , `ContentLink` , `Duration` ) SELECT `Id` , `P_BatchId` , `P_ContentPath` , `ContentTitle` , `ContentTypeId` , NOW ( ) , `ContentLink` , `Duration` FROM `tteachercontent` WHERE `ContentPath` IN ( SELECT `concat` ( `ContentPath` , ? , `Id` , ? , `ContentTitle` ) FROM `tteachercontent` WHERE `id` = `P_ContentId` ) AND `ContentTypeId` IN (...) ; END IF ; INSERT INTO `tteachercontentassign` ( 