CREATE PROCEDURE `spCreateBatch` ( IN `P_TeacherId` INTEGER (?) , IN `P_StudentId` VARCHARACTER (?) , IN `P_InstituteId` INTEGER (?) , IN `P_Code` VARCHARACTER (?) , IN `P_Title` VARCHARACTER (?) , IN `P_BatchDate` DATE ) BEGIN DECLARE `P_BatchId` INTEGER DEFAULT ? ; DECLARE `P_Values` VARCHARACTER (?) DEFAULT ? ; DECLARE `P_Insert` VARCHARACTER (?) DEFAULT ? ; DECLARE `P_UserId` INTEGER DEFAULT ? ; IF NOT EXISTS ( SELECT ? FROM `tteacher` WHERE `Id` = `P_TeacherId` ) THEN SELECT ? ; ELSEIF EXISTS ( SELECT ? FROM `tbatch` WHERE `TeacherId` = `P_TeacherId` AND `Title` = `P_Title` ) THEN SELECT ? ; ELSEIF NOT EXISTS ( SELECT ? FROM `tinstitute` WHERE `Id` = `P_InstituteId` ) THEN SELECT ? ; ELSE BEGIN START TRANSACTION ; INSERT INTO `tbatch` ( `TeacherId` , CODE , `Title` , `BatchDate` , `CreatedDateTime` , `UpdatedDateTime` ) VALUES ( `P_TeacherId` , `P_Code` , `P_Title` , `P_BatchDate` , NOW ( ) , NOW ( ) ) ; SET `P_BatchId` = `LAST_INSERT_ID` ( ) ; SET `P_UserId` = ( SELECT `UserId` FROM `tteacher` WHERE `Id` = `P_TeacherId` ) ; INSERT INTO `tchatgroupmaster` ( `Title` , `CreatedUserId` , `CreatedDateTime` , `BatchId` ) VALUES ( `P_Title` , `P_UserId` , NOW ( ) , `P_BatchId` ) ; IF NOT `P_StudentId` = ? THEN SET `P_Values` = REPLACE ( `P_StudentId` , ? , `CONCAT` ( ? , `P_BatchId` , ?, ... ) ) ; SET 