Iain Fifer
Iain Fifer

Reputation: 123

MySQL multiple if statement executions

I want to be able to perform two executions in my if statement. I am getting an error on the last semi colon:

If(condition)
THEN
SET table.column = table1.column;
INSERT INTO errortable (column) VALUES ("Error");
END IF;

This also does not work:

If(condition)
THEN
SET table.column = table1.column,
INSERT INTO errortable (column) VALUES ("Error");
END IF;

Nor this:

If(condition)
THEN
SET table.column = table1.column
INSERT INTO errortable (column) VALUES ("Error");
END IF;

Thanks

Upvotes: 1

Views: 7689

Answers (2)

C.B.
C.B.

Reputation: 686

"BEGIN ... END syntax is used for writing compound statements", according to the docs: http://dev.mysql.com/doc/refman/5.6/en/begin-end.html

Also, i believe the parentheses matter: "There is also an IF()function, which differs from the IFstatement described here. See Section 12.4, “Control Flow Functions”. The IF statement can have THEN, ELSE, and ELSEIF clauses, and it is terminated with END IF." -- http://dev.mysql.com/doc/refman/5.6/en/if.html

Upvotes: 2

1615903
1615903

Reputation: 34780

You are using If() function instead of If statement. Remove the brackets from the condition.

Upvotes: 1

Related Questions