I'm working on a data migration script. It will move data from one database to another with a new, different format.
At one point, I need to insert about 6 records, which map some old scattered IDs onto some new contiguous ones. E.g., 1 becomes 1, 2 becomes 2....9 becomes 5, 10 becomes 6.
Since I have to run a number of insert queries that all use this mapping, i thought it wise to create a function which uses a case statement. This code is giving me an error:
CREATE FUNCTION DEPT_ID_TO_CAT_ID (deptID INT(2))
RETURNS INT
DETERMINISTIC
BEGIN
DECLARE catID INT;
SET catID = CASE deptID
WHEN 1 THEN 1
WHEN 2 THEN 2
WHEN 3 THEN 3
WHEN 4 THEN 4
WHEN 9 THEN 5
WHEN 10 THEN 6
ELSE NULL
END;
RETURN catID;
END
The error I get is "#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'INT' at line 5 "
I'm using MySQL v. 5. Any help would be much appreciated. And let me know if this is a stupid way to go about this.