I’m trying to add an IF clause inside an update statement. Thought this was easy, but seems it isn’t.
This is the way it is. It’s inside a stored procedure.
FETCH cur1 INTO procId, procType, procVals, procLen, procUpdated, procPrivate, procRegional;
IF done THEN
LEAVE the_loop;
END IF;
UPDATE scores t1
JOIN scores t2
ON FIND_IN_SET(t1.id, t2.vals)
SET t1.private = t1.private+1,
IF procType = 3 THEN // Problem lies here
t1.regional = t1.regional+1;
ELSE IF procType = 4 THEN
t1.otherCol = t1.otherCol+1;
END IF;
WHERE t2.id = procId;
I’m stuck with the IF
in there. Apart from the first SET
, I also need to Update
another column with the IF
. Can you please assist?
I also did like below, but everthime it’s the same error:
SQL Error (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 'CASE procType
UPDATE scores t1
JOIN scores t2
ON FIND_IN_SET(t1.id, t2.vals)
SET t1.private = t1.private+1,
CASE
WHEN procType = 3 THEN t1.regional = t1.regional+1
WHEN procType = 4 THEN t1.otherCol = t1.otherCol+1
END as Col
WHERE t2.id = procId