samedi 30 avril 2016

mysql different row updates depending on a variable (stored procedure)

CREATE PROCEDURE update_table(
    IN choice INT(4),
    IN id VARCHAR(50),
    IN string VARCHAR(50)
)
BEGIN
UPDATE salesman
set salesman_name = IF(choice = 1, string, salesman_name)
where salesman_id = id
UPDATE salesman
set date = IF(choice = 2, string, date)
where salesman_id = id
END

if choiceis 1, change salesman_name as string

if choice is 2, change date as string

can you explain me what i'm doing wrong?

it works fine with a single update, my guess is there is another way to implement if but i couldn't.

if choice = 1 then
update salesman set salesman_name = string where salesman_id = id

...i tried this version too but still, not working.

Aucun commentaire:

Enregistrer un commentaire