CREATE PROCEDURE `spAlertGetTestData` ( IN `P_TestId` INTEGER , IN `P_Template` VARCHARACTER (?) , IN `P_TeacherId` INTEGER , IN `P_BatchId` INTEGER , IN `P_MailSubject` VARCHARACTER (?) , IN `P_StudentId` INTEGER , IN `P_RoleTypeId` INTEGER ) BEGIN IF `P_RoleTypeId` = ? THEN IF ( `P_StudentId` = ? ) THEN SELECT `ET` . `Id` , `B` . `TeacherId` , `B` . `Id` AS `BatchId` , `B` . `Title` AS `BatchName` , `S` . `Id` AS `StudentId` , `U` . `MobileNo` AS `MobileNo` , `ET` . `Topic` AS `Title` , `IFNULL` ( `S` . `EmailId` , ? ) AS `EmailId` , REPLACE ( REPLACE ( `P_Template` , ? , `U` . `Name` ) , ? , CASE WHEN `floor` ( SQL_TSI_HOUR ( `timediff` ( `concat` ( `ET` . `StartDate` , ? , `ET` . `StartTime` ) , NOW ( ) ) ) / ? ) > ? THEN `Concat` ( `floor` ( SQL_TSI_HOUR ( `timediff` ( `concat` ( `ET` . `StartDate` , ? , `ET` . `StartTime` ) , NOW ( ) ) ) / ? ) , ? ) WHEN SQL_TSI_HOUR ( `timediff` ( `concat` ( `ET` . `StartDate` , ? , `ET` . `StartTime` ) , NOW ( ) ) ) > ? THEN `Concat` ( `floor` ( SQL_TSI_HOUR ( `timediff` ( `concat` ( `ET` . `StartDate` , ? , `ET` . `StartTime` ) , NOW ( ) ) ) ) , ? ) ELSE `Concat` ( 