CREATE PROCEDURE `spAlertGetTimeTable` ( IN `P_Template` VARCHARACTER (?) , IN `P_MailSubject` VARCHARACTER (?) , IN `P_BatchId` INTEGER , IN `P_TeacherId` INTEGER , IN `P_IsSession` BIT , IN `P_TimeTableId` INTEGER ) BEGIN IF ( `P_TimeTableId` = ? ) THEN IF ( `P_IsSession` = ? ) THEN SELECT `TT` . `Id` , `B` . `Title` AS `BatchName` , `T` . `Id` , `U` . `MobileNo` , `IFNULL` ( `S` . `EmailId` , ? ) AS `EmailId` , REPLACE ( REPLACE ( REPLACE ( `P_Template` , ? , `U1` . `Name` ) , ? , `ifnull` ( `TT` . `FromDate` , ? ) ) , ? , `B` . `Title` ) AS `MsgText` , `P_MailSubject` AS SUBJECT , ? AS `ReceiverRoleTypeId` , `S` . `Id` AS `ReceiverSourceId` , `S` . `UserId` AS `ReceiverUserId` , `T` . `UserId` AS `UserId` , `T` . `InstituteId` AS `InstituteId` , `B` . `Id` AS `BatchId` FROM `ttimetable` `TT` LEFT JOIN `tbatch` `B` ON `B` . `Id` = `TT` . `BatchId` LEFT JOIN `tteacher` `T` ON `T` . `Id` = `B` . `TeacherId` LEFT JOIN `tassignbatch` `AB` ON `AB` . `BatchId` = `B` . `Id` LEFT JOIN `tstudent` `S` ON `AB` . `StudentId` = `S` . `Id` LEFT JOIN `tuser` `U` ON `S` . `UserId` = `U` . `Id` 