2

How can I add parameters with NULL default value for MySQL stored procedure?

Patrick Allaert
  • 1,751
  • 18
  • 44
Raed Alsaleh
  • 1,581
  • 9
  • 27
  • 50
  • 'case when` could be used. Post what you have tried please. – bonCodigo Dec 30 '12 at 13:30
  • I tried to add it but, it does not work, thanx – Raed Alsaleh Dec 30 '12 at 13:45
  • duplicate: http://stackoverflow.com/questions/12652241/writing-optional-parameters-within-stored-procedures-in-mysql – Patrick Allaert Feb 06 '14 at 09:42
  • possible duplicate of [Is it possible to have a default parameter for a mysql stored procedure?](http://stackoverflow.com/questions/982798/is-it-possible-to-have-a-default-parameter-for-a-mysql-stored-procedure) – Pang Aug 21 '14 at 03:22

2 Answers2

2

According to this answer MySQL does not support true 'default parameters' in functions or stored procedures.

This answer on the same page provides a solution that may work for you.

Community
  • 1
  • 1
losthorse
  • 1,530
  • 1
  • 13
  • 33
0

Any query with variable and 'case`:-

BEGIN 
    DECLARE @NullValue:=Null;  
    SELECT 
    CASE WHEN Sum(myField) Is Null 
    THEN @NullValue ELSE Sum(myField)
    END AS Total 
    FROM table_name; 
END
;
bonCodigo
  • 14,268
  • 1
  • 48
  • 91