CREATE PROCEDURE `spCreateTeacher` ( IN `P_Code` VARCHARACTER (?) , IN `P_UserId` INTEGER ) BEGIN IF EXISTS ( SELECT * FROM `tteacher` WHERE `UserId` = `P_UserId` ) THEN SELECT `P_UserId` ; ELSE INSERT INTO `tteacher` ( CODE , `UserId` , `CreatedDateTime` , `UpdatedDateTime` , `InstituteId` ) VALUES ( `P_Code` , `P_UserId` , NOW ( ) , NOW ( ) , ? ) ; SELECT `LAST_INSERT_ID` ( ) ; END IF ; END 