title: Syntax error on DECLARE
body: <p>I want to use the serial of an insert directly in a next insert.</p>
  
  <p>Based on <a href="https://stackoverflow.com/questions/5147989/help-with-t-sql-script-insert-record-then-use-identity-of-that-insert-on-anoth">Help with T-SQL script: Insert record, then use identity of that insert on another statement?</a> I execute the following SQL query:</p>
  
  <pre><code>DECLARE @Id1 BIGINT
  DECLARE @Id2 BIGINT
  INSERT INTO doses (CPS, ground, total) VALUES (10, 10, 10)
  SET @Id1 = SELECT SCOPE_IDENTITY()
  INSERT INTO places (x, y, z, speed) VALUES (10, 10, 10, 10)
  SET @Id2 = SELECT SCOPE_IDENTITY()
  INSERT INTO measurements (time, place, note, dose, id_dataset) VALUES ('Test', @Id1, 'test', @Id2, 17)
  </code></pre>
  
  <p>This give me a syntax error and I can't find anything wrong with my DECLARE.</p>
  
  <pre><code>#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 'DECLARE @Id1 BIGINT
  DECLARE @Id2 BIGINT INSERT INTO doses (CPS, ground, total)' at line 1 
  </code></pre>
  
  <p>It seems that DECLARE in MySQL can only be used in a BEGIN..END. <a href="http://dev.mysql.com/doc/refman/5.0/en/declare.html" rel="nofollow noreferrer">http://dev.mysql.com/doc/refman/5.0/en/declare.html</a></p>
  
  <p>Also SCOPE_IDENTITY is replace with LAST_INSERT_ID().</p>
  
  <p>This is my new query:</p>
  
  <pre><code>BEGIN
  
  DECLARE @Id1 BIGINT;
  DECLARE @Id2 BIGINT;
  
  INSERT INTO doses (CPS, ground, total) VALUES (10, 10, 10);
  SET @Id1 = (SELECT LAST_INSERT_ID());
  
  INSERT INTO places (x, y, z, speed) VALUES (10, 10, 10, 10);
  SET @Id2 = (SELECT LAST_INSERT_ID());
  
  INSERT INTO measurements (time, place, note, dose, id_dataset);
  VALUES ('Test', @Id1, 'test', @Id2, 17);
  
  END
  </code></pre>
  
  <p>But I still get the same error.</p>