How to use optional parameters in a MySQL Stored Procedure
I want to modify a SP in MySQL, but don't want it to crash apps currently using that SP.
The SP is: SP_CreateUserReport
Argument 1: Check4ItCode
Argument 2: PasscodeAdmin
Currently, the calling app sends something like:
Call SP_CreateUserReport('CfiCode','12324')
But I want to add a new argument to the SP:
Argument 3: DemoUserEmail
When I do that, and do the same call, the SP will not receive the 3rd new argument and fail.
Eventually, I will update the all the calls from various apps to add the 3rd argument value, But in the meantime, I want to make that 3rd argument optional till I can update all the calling apps. And, if that value is not there, store a NULL in the table for that field.
Here is a sample of the final code I wish to use.
DELIMITER $$CREATE DEFINER=`root`@`localhost` PROCEDURE `SP_CreateUserReport`(Check4ItCode varchar(255) ,PasscodeAdmin varchar(255),DemoUserEmail varchar(255) )BEGININSERT INTO tbl_000_010_MAIN_REPORT_INFO ( strCFICode, strPasscodeAdmin, strDemoUserEmail)SELECT Check4ItCode as CFICode, PasscodeAdmin AS AdminCode, DemoUserEmail as TheDemoUserEmailSELECT LAST_INSERT_ID() as NewReportID;END
John