I have a MySQL table with this configuration
I want to perform following operation:
let's assume a variable amount = some_value
for each row in ingridients_entry {
IF amount = 0
break;
END IF
IF amount > count - consumed
SET amount = amount - (count-consumed) AND consumed = count
ELSE
SET consumed = consumed + amount AND amount = 0
END IF
}
Is it possible with the sql UPDATE query?
I was thinking about using case with update in a procedure like this
DELIMITER $$
CREATE PROCEDURE consumeIngridients(IN amount FLOAT, IN sr INT)
BEGIN
update ingridients_entry set consumed=CASE
WHEN amount = 0 THEN consumed
WHEN amount > (count - consumed) THEN SET amount = amount - (count - consumed); count
ELSE consumed + amount;SET amount = 0;
END CASE;
where serial=sr and count>consumed;
END$$
DELIMITER ;
But it is giving me error:
ERROR 1064 (42000): 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 'SET amount = amount - (count - consumed); count ELSE consumed + amount;SET amoun' at line 5
Please help!