CREATE PROCEDURE `spGetBatch` ( IN `P_BatchId` INTEGER (?) , IN `P_IntituteId` INTEGER (?) , IN `P_TeacherId` INTEGER (?) , IN `P_StudentId` INTEGER , IN `P_IsOrderBy` INTEGER ) BEGIN IF `P_StudentId` = ? THEN SELECT `tbatch` . `Id` AS `BatchId` , `tbatch` . `code` AS `BatchCode` , `tbatch` . `title` AS `Title` , `tbatch` . `BatchDate` AS `BatchDate` , `tbatch` . `CreatedDateTime` , ( SELECT COUNT ( `BatchId` ) FROM `tassignbatch` WHERE `StatusId` = ? AND `BatchId` = `tbatch` . `Id` ) AS `JoinedStudentCount` , ( SELECT COUNT ( `BatchId` ) FROM `tassignbatch` WHERE `StatusId` = ? AND `BatchId` = `tbatch` . `Id` ) AS `NotJoinedStudentCount` FROM `tbatch` LEFT JOIN `tteacher` ON `tteacher` . `Id` = `tbatch` . `TeacherId` LEFT JOIN `tassignbatch` ON `tassignbatch` . `BatchId` = `tbatch` . `Id` WHERE ( `tbatch` . `TeacherId` = `P_TeacherId` ) AND ( `tteacher` . `InstituteId` = `P_IntituteId` ) AND ( `tbatch` . `Id` = `P_BatchId` OR `P_BatchId` = ? ) GROUP BY `tbatch` . `Id` ORDER BY CASE WHEN `P_IsOrderBy` = ? THEN `tbatch` . `id` WHEN `P_IsOrderBy` = ? THEN `tbatch` . `title` END ASC , CASE WHEN `P_IsOrderBy` = ? THEN 