MySQL Error 1064: Creating a procedure -
i modifying procedure of mine. since switched webspace provider , don't allow sql-trigger, need following in procedure:
after comment created recruitment, recruitments "last activity"-field has updated. created comment id should returned.
i tried this:
begin declare id int; insert `comments` ( `comments`.`recruitment_id`, `comments`.`user_id`, `comments`.`comment` ) values ( recruitment_id, user_id, com ); select last_inserted_id() id; update `recruitments` set `recruitments`.`lastactivity` = `comments`.`creationdate` inner join `comments` on `recruitments`.`id` = `comments`.`recruitment_id` `comments`.`id` = id; select id; end
but error:
#1064 - have error in sql syntax; check manual corresponds mysql server version right syntax use near 'inner join `comments` on `recruitments`.`id` = `comments`' @ line 25
i bet it's small mistake again can't seem find =(
try writing body this:
begin declare v_id int; insert comments(recruitment_id, user_id, comment) values (v_recruitment_id, v_user_id, v_com); select v_id := last_inserted_id(); update recruitments r inner join comments c on r.id = c.recruitment_id set r.lastactivity = c.creationdate c.id = v.id; select v_id; end;
there several issues query:
- identify parameters prefix not confused columns in query.
- identify variables prefix well.
- don't qualify column names in column list
select
. - the proper syntax
update
join
in mysql putjoin
logic right afterupdate
.
Comments
Post a Comment