CREATE PROCEDURE `spSelectInstitute` ( IN `P_UserId` INTEGER , IN `P_InstituteId` INTEGER , IN `P_OSTypeId` SMALLINT , IN `P_DeviceToken` VARCHARACTER (?) ) BEGIN DECLARE `roletype` INTEGER DEFAULT ? ; DECLARE `V_SourceId` INTEGER DEFAULT ? ; SET `roletype` = ( SELECT `RoleTypeId` FROM `tuser` WHERE `Id` = `P_UserId` ) ; IF ( `roletype` = ? ) THEN IF EXISTS ( SELECT ? FROM `tstudent` WHERE `UserId` = `P_UserId` AND `InstituteId` = `P_InstituteId` ) THEN UPDATE `tstudent` SET `StatusId` = ? WHERE `UserId` = `P_UserId` AND `InstituteId` = `P_InstituteId` AND ( `StatusId` = ? OR `StatusId` IS NULL ) ; SELECT ? ; SET `V_SourceId` = ( SELECT `Id` FROM `tstudent` WHERE `UserId` = `P_UserId` AND `InstituteId` = `P_InstituteId` ) ; ELSE SELECT ? ; END IF ; ELSEIF ( `roletype` = ? ) THEN IF EXISTS ( SELECT ? FROM `tteacher` WHERE `UserId` = `P_UserId` AND `InstituteId` = `P_InstituteId` ) THEN UPDATE `tteacher` SET `DateOfJoining` = NOW ( ) , `UpdatedDateTime` = NOW ( ) WHERE `UserId` = `P_UserId` AND `InstituteId` = `P_InstituteId` AND `UpdatedDateTime` IS NULL ; SELECT ? ; SET `V_SourceId` = ( SELECT `Id` FROM `tteacher` WHERE `UserId` = `P_UserId` AND `InstituteId` = `P_InstituteId` ) ; ELSE SELECT ? ; END IF ; END IF ; IF ( 