CASEcase_valueWHENwhen_valueTHENstatement_list[WHENwhen_valueTHENstatement_list] ... [ELSEstatement_list] END CASE
Or:
CASE
WHEN search_condition THEN statement_list
[WHEN search_condition THEN statement_list] ...
[ELSE statement_list]
END CASE
The CASE statement for stored routines
implements a complex conditional construct. If a
search_condition evaluates to true,
the corresponding SQL statement list is executed. If no search
condition matches, the statement list in the
ELSE clause is executed. Each
statement_list consists of one or
more statements.
Note: The syntax of the
CASE statement shown
here for use inside stored routines differs slightly from that
of the SQL CASE
expression described in
Section 12.3, “Control Flow Functions”. The
CASE statement cannot have an ELSE
NULL clause, and it is terminated with END
CASE instead of END.

User Comments
The CASE statement requires all possible outcomes to be catered for. This implies that the ELSE conditions are effectively mandatory unless you are absolutely certain you've provided a WHEN clause to cover every possible situation when entering the CASE statement.
The CASE statement can provides the choose situatuion one's, acording with the return or get data value, so:
mysql> DELIMITER //
--> CREATE PROCEDURE my_dinamicSelect(IN var INT)
--> BEGIN
--> CASE var
--> WHEN 1 THEN SELECT 'First statement';
--> WHEN 2 THEN SELECT 'Second statement';
--> ELSE 'Other statement else...';
--> END CASE;
--> END //
Bye...
CASE sType
WHEN 'ret' THEN
UPDATE tablename SET felt1 = '', felt2 = '' WHERE felt3 = '';
WHEN 'new' THEN
INSERT INTO tablename SET felt1 = '', felt2 = '', felt3 = '';
WHEN 'del' THEN
DELETE FROM tablename WHERE felt3 = '';
END CASE;
i get problems to get my CASE to work bot this work :) i hob its help more pepole.
Add your own comment.