944,087 Members | Top Members by Rank

Ad:
  • MySQL Discussion Thread
  • Unsolved
  • Views: 4252
  • MySQL RSS
Nov 29th, 2007
0

Problem on IF STATEMENT on TRIGGER with MySql

Expand Post »
Hi Everybody,

i found out that to create a trigger i have to remove the BEGIN and END and it works, but as i put an IF STATEMENT inside like this one:

CREATE TRIGGER status_history_upd AFTER UPDATE ON projects
FOR EACH ROW

IF NEW.project_status != OLD.project_status THEN
INSERT INTO project_status_history
SET status_change_date = NEW.project_edit_date,
project_id = NEW.project_id,
status_id = NEW.project_status;
END IF;

for some reason it gives me back this error:

MySQL said:
#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 'INSERT INTO project_status_history
SET status_change_date = NEW.project_edi' at line 5

I really have to put the IF statement because i need to run the INSERT just in some cases.

Can someone please help?

Thanks

Gabriele
Reputation Points: 10
Solved Threads: 0
Newbie Poster
ihaveguts is offline Offline
1 posts
since Nov 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in MySQL Forum Timeline: 3 condition query
Next Thread in MySQL Forum Timeline: Same query, one difference





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC