2

Please, know I'm learning MySQL as my application continues to grow. Please keep that in mind should you be kind enough to answer my question.

I'm trying to achieve the following

I added a new row to my table, keeping track of the game number in the round, thus it will have values 1,2,3,4.... when round ends it will be reset to 1 etc

I read in the MySQL manual about loops and came up with this, however it says my syntax is wrong, I would appreciate it if a more experienced user may look this over for me.

CREATE PROCEDURE inc()
    BEGIN
      DECLARE v1 INT 

      WHILE `round` ='1'

        SET v1 = v1 + 1;
    update events set `round_game_nr` ='v1'
      END WHILE;
    END;

I'm trying to achieve this

enter image description here

where 1st column is round and 2nd column is nr of games

1
  • you had missing ; after update, and WHILE .... DO Commented May 18, 2015 at 7:24

1 Answer 1

1
CREATE PROCEDURE inc()
BEGIN
  DECLARE v1 INT;    --semicolon missing

  WHILE `round` ='1' DO    --Do missing

    SET v1 = v1 + 1;
    UPDATE events SET `round_game_nr` =v1;   --semicolon missing, v1 should not with ``
  END WHILE;
END;
Sign up to request clarification or add additional context in comments.

5 Comments

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 '' at line 3 `
hmmmm,im running this in phpmyadmin maybe that has some effect...ill investigate and let you knw, thanks mate
I also get this "error at line 3" with your online syntax checker. The usual way of commenting MySQL is -- , two dashes and blank, or #, or /* ... */.
@TimothyCoetzee maybe because of your variable naming, I used those variable without ` ` just directly while round = '1' DO and so on
@peter_the_oak lolz, I not sure how to commenting in MYSQL also, but you should know..... you can remove it =_=

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.