Equivalent of Switch Statement in MySql 5
Posted
by Robert Gowland
on Stack Overflow
See other posts from Stack Overflow
or by Robert Gowland
Published on 2010-06-02T17:12:59Z
Indexed on
2010/06/02
17:13 UTC
Read the original article
Hit count: 250
Using MySql 5, I have a task where I need to update one table based on the contents of another table.
For example, I need to add 'A1' to table 'A' if table 'B' contains 'B1'. I need to add 'A2a' and 'A2b' to table 'A' if table 'B' contains 'B2', etc.. In our case, the value in table 'B' we're interested is an enum.
Right now I have a stored procedure containing a series of statements like:
INSERT INTO A
SELECT 'A1'
FROM B
WHERE B.Value = 'B1';
--Repeat for 'B2' -> 'A2a', 'A2b'; 'B3' -> 'A3', etc...
Is there a nicer more DRY way of accomplishing this?
© Stack Overflow or respective owner