title: MySQL INSERT IF condition is true
body: <p>I'm making a stored routine in MySQL, and I would like to know whether it is possible to make an INSERT-IF some condition is TRUE, ELSE INSERT something else.</p>
  
  <p>This is My Query but I keep getting the #1064 Error (SQL Syntax Error).</p>
  
  <pre><code>DECLARE a INT;
  DECLARE b INT;
  DECLARE changeTypeID INT DEFAULT(0);
  
  SET a = (SELECT roomPrice FROM RPH WHERE tier=1 AND 
  startDate = '2018-02-20' AND rTypeID=1);
  SET b = (SELECT roomPrice FROM RPH WHERE tier=1 AND 
  startDate = '2018-02-20' AND rTypeID=2);
  
  SET changeTypeID = CASE WHEN (a&gt;b) THEN 1 WHEN (a&lt;b) THEN 2 WHEN a=b THEN 3 END;
  IF (changeTypeID = 1 OR changeTypeID =2) THEN
  (
  INSERT INTO TABLE_A (X,Y,Z) VALUES (ID, changeTypeID, createdBy);
  )
  ELSEIF (changeTypeID = 3) THEN
  (
  INSERT INTO TABLE_B (P,Q,R) VALUES (ID, rID, createdBy);
  )
  END IF;
  </code></pre>
  
  <p>Here is the error message: </p>
  
  <pre><code>SQL Error (1064): You have an error in your SQL Syntax; check the manual
  that corresponds to your MySQL version for the right syntax to use near
  'INSERT INTO TABLE_A (X,Y,Z)' at line 19
  </code></pre>
  
  <p>Note: The insert parameter is already declared on the routine beforehand.</p>
  
  <p>Any help will be appreciated :)</p>