Link to home
Start Free TrialLog in
Avatar of askolits
askolits

asked on

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) 
)

BEGIN
INSERT INTO tbl_000_010_MAIN_REPORT_INFO ( 
strCFICode, 
strPasscodeAdmin, 
strDemoUserEmail)

SELECT 
Check4ItCode as CFICode, 
PasscodeAdmin AS AdminCode, 
DemoUserEmail as TheDemoUserEmail

SELECT LAST_INSERT_ID() as NewReportID;
END

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Walter Ritzel
Walter Ritzel
Flag of Brazil image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of askolits
askolits

ASKER

Oh well, I left a comment on the MySQL link you sent. Thanks for your help.

John