mariadb - Mysql Procedure IF,ELSEIF Statment error -


i try create procedure in mysql, syntax error, don`t know why , ''

# 1064 - have error in rsql syntax next '' on line 4

my procedure:

create procedure muwap_vipadd(in szcharname varchar(10),in dayadd int,in viptype smallint,in datenow_srv datetime) begin if not exists (select 1 `t_viplist` accountid = szcharname) insert `t_viplist` (`accountid`,`date`,`type`) values (szcharname,date_add(datenow_srv, interval dayadd day),viptype); else if exists (select 1 `t_viplist`  accountid = szcharname , date > datenow_srv) update `t_viplist` set `date` = date_add(`date`,interval dayadd day) `accountid` = szcharname; update `t_viplist` set `type` = viptype `accountid` = szcharname , `type` < viptype; else  update `t_viplist` set `date` = date_add(`date`,interval dayadd day), `type` = viptype `accountid` = szcharname; end if end 

thank you!

in order have multiple statements in then statement, need use begin...end.

create procedure muwap_vipadd(in szcharname varchar(10),in dayadd int,in viptype smallint,in datenow_srv datetime) begin     if not exists (select 1 `t_viplist` accountid = szcharname)      insert `t_viplist` (`accountid`,`date`,`type`) values (szcharname,date_add(datenow_srv, interval dayadd day),viptype);     else if exists (select 1 `t_viplist`  accountid = szcharname , date > datenow_srv)      begin         update `t_viplist` set `date` = date_add(`date`,interval dayadd day) `accountid` = szcharname;         update `t_viplist` set `type` = viptype `accountid` = szcharname , `type` < viptype;     end     else update `t_viplist` set `date` = date_add(`date`,interval dayadd day), `type` = viptype `accountid` = szcharname;     end if end 

you combine 2 update queries single query:

update t_viplist set date = date_add(date, interval dayadd day),     type = greatest(viptype, type) accountid = szcharname; 

in fact, seems whole thing done single insert ... on duplicate key update query:

insert t_viplist (accountid, date, type) values (szcharname,date_add(datenow_srv, interval dayadd day),viptype) on duplicate key update     date = if(date > datenow_srv, values(date), date),     type = greatest(type, values(type)); 

Comments

Popular posts from this blog

What is happening when Matlab is starting a "parallel pool"? -

angular - DownloadURL return null in below code -

php - Cannot override Laravel Spark authentication with own implementation -