CREATE PROCEDURE `spCreatePaymentTransaction` ( IN `P_FeeId` INTEGER , IN `P_StudentId` INTEGER , IN `P_PaymentAmount` INTEGER , IN `P_TransactionStatusId` INTEGER , IN `P_PaymentRemark` VARCHARACTER (?) , IN `P_OSTypeId` SMALLINT , IN `P_DateOfFeeCollection` DATE ) BEGIN IF EXISTS ( SELECT ? FROM `tfeesetup` WHERE `Id` = `P_FeeId` AND `StudentId` = `P_StudentId` ) THEN START TRANSACTION ; INSERT INTO `tpaymenttransaction` ( `FeeSetupId` , `StudentId` , `PayAmount` , `PayDateTime` , `PaymentRemark` , `TransactionStatusId` , `DateOfFeeCollection` ) VALUES ( `P_FeeId` , `P_StudentId` , `P_PaymentAmount` , NOW ( ) , `P_PaymentRemark` , `P_TransactionStatusId` , `P_DateOfFeeCollection` ) ; SELECT `LAST_INSERT_ID` ( ) AS `Result` ; COMMIT ; ELSE SELECT ? AS `Result` ; END IF ; END 