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

DatabasesMySQL ServerSQL

Avatar of undefined
Last Comment
askolits

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Walter Ritzel

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
askolits

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

John
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes