| | |
Problem on IF STATEMENT on TRIGGER with MySql
Please support our MySQL advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Nov 2007
Posts: 1
Reputation:
Solved Threads: 0
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
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
![]() |
Other Threads in the MySQL Forum
- Previous Thread: 3 condition query
- Next Thread: Same query, one difference
| Thread Tools | Search this Thread |
agplv3 alfresco amazon api artisticlicense aws bizspark breathalyzer camparingtocolumns changingprices cmg communityjournalism contentmanagement contractors copyright count court crm database design developer development distinct drupal dui ec2 email enterprise eudora facebook form foss gartner government gpl greenit groklaw groupware hiring hyperic images innerjoins insert ip joebrockmeier join journalism keyword keywords kickfire laptop law legal license licensing linux maintenance managing mariadb matchingcolumns metron micromanage microsoft mindtouch montywidenius mozilla multiple music mysql mysqlcolumnupdating mysqldatetimeordermax() mysqlindex mysqlinternalqueries mysqlquery news open-xchange opendatabasealliance opengovernment opensource oracle penelope php priceupdating query referencedesign reorderingcolumns resultset saas select sharepoint simpledb sourcecode spotify sql sugarcrm syntax techsupport thunderbird transparency virtualization





