MySQL Stored Procedure example. You cannot use BEGIN end in if else. Otherwise, an error code: 1064 is reported!

Source: Internet
Author: User
Tags rounds stored procedure example

Error 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

The error is reported because the if else statement in MySQL procedure uses the begin end statement. If it is removed, it is OK.

 

Delimiter $ use 'sportgbmj '$ drop procedure if exists 'SP _ web_addmiddayrank' $ create definer = 'root' @ '% 'Procedure 'SP _ web_addmiddayrank '() begin/* revision record: Supervisor version revised by revision date revision description 2.161.0.0 2013-06-15 query current Am-Am rankings this SP is executed after the end of the current competition prerequisites: 1: must complete 10 (inclusive) bureaus or above in one field */declare I _date date; declare I _starttime time; declare I _endtime time; Set I _date = now (); Set I _endtime = now (); if (I _endtime> '22: 30') then Begin /* Night arena */set I _starttime = '21: 30'; Set I _endtime = '22: 30 '; End Else Begin /* Midday field */set I _starttime = '12: 30'; Set I _endtime = '13: 30 '; End End if; create temporary table tmp_rank (ID int not null auto_increment -- Auto increment, userid int -- User ID, beans int -- bean summary, rounds tinyint -- number of Bureaus summary, posttime time -- time (the player's last time in the game) engine = MyISAM; insert into tmp_rank (userid, beans, rounds, posttime) Select userid, sum (case when consume> 0 then consume else 0 end) Beans, count (userid) rounds, max (posttime) as posttime from score as s inner join scorelist as SL on S. PID = SL. PID where roomid in ('20140901') and (postdate = I _date and posttime> = '12: 30: 00' and posttime <= '13: 30: 00 ') group by userid having (rounds> = 10) order by beans DESC, maxtime ASC limit 500;/* Insert a table */insert into hf_playranklist (userid, rank, beans, rounds, postdate, posttime) Select userid, beans, rounds, I _date, posttime from tmp_rank;/* Insert prize table */INSERT INTO hf_prizelist (userid, status, prizeid, receivetime, postdate) Select userid, 0, (case when Id> = 11 then 4 when (ID> = 3 and ID <= 10) then 3 when id = 2 then 2 when id = 1 then 1 end) as prizeid, beans, rounds, posttime from tmp_rank as R where rank> = 30; end $ delimiter;

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.