Keep Getting a Syntax Error when Creating MySQL Trigger -
i trying create trigger fire after insert of record see if there other records similar inserted record (same date) , if update column in inserted record. once complete 1 update after update well. appreciated.
create trigger `insert_postdateindex` after insert on `zoomloca_listings-dev`.`listings_posts` each row begin declare vnewpostdateindex int; declare vlastpostdateindex int default '0'; set vnewpostdateindex = '0'; set vlastpostdateindex = (select postdateindex listings_posts date(post_date) = date(new.post_date) order postdateindex desc limit 1); if vlastpostdateindex = '0' set vnewpostdateindex = '0'; else set vnewpostdateindex = vlastpostdateindex + 1; end if; update `listings_posts` set postdateindex = vnewpostdateindex id = new.id; end error: #1064 - have error in sql syntax; check manual corresponds mysql server version right syntax use near '' @ line 6
the problem there no top in mysql. have use limit instead. besides, if not using mysql client, should remove delimiter since not feature of mysql. thing demarcate end of if statement in mysql, should use end if instead of endif.
Comments
Post a Comment