I am trying to run the following script in mysql :
DELIMITER $$$
DROP TRIGGER IF EXISTS invoice_line_insert
$$$
CREATE TRIGGER invoice_line_insert AFTER INSERT
ON invoice_line FOR EACH ROW
BEGIN
IF NEW.type = "DELIVERY" THEN
UPDATE invoice
SET invoice.etdelivery_amount = invoice.etdelivery_amount + NEW.amount
WHERE invoice.id_invoice = NEW.invoice_parent_id_invoice;
ELSE
UPDATE invoice
SET invoice.etexpense_amount = invoice.etexpense_amount + NEW.amount
WHERE invoice.id_invoice = NEW.invoice_parent_id_invoice;
END IF;
UPDATE invoice
SET invoice.vatamount = (NEW.amount * ((
SELECT vat.rate
FROM vat
WHERE vat.id_vat = NEW.vat_id_vat
) / 100)) + invoice.vatamount
WHERE invoice.id_invoice = NEW.invoice_parent_id_invoice;
UPDATE invoice
SET invoice.itamount = invoice.vatamount +
invoice.etdelivery_amount +
invoice.etexpense_amount
WHERE invoice.id_invoice = NEW.invoice_parent_id_invoice;
END
$$$
When I run it in mySql Workbench, it is working fine, but when play 2 run it authomatically (in a file called 2.sql) I get the following error :
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 'DELIMITER $$$ DROP TRIGGER IF EXISTS invoice_line_insert $$$ CREATE TRIGGER invo' at line 1 [ERROR:1064, SQLSTATE:42000], while trying to run this SQL script:
I read on the internet that the delimiter statement is only working on specific gui, not every time. Is that true ? Why ? How to resolve it because I need the delimiter statement ?
Thanks for your help.
DROP TRIGGER IF EXISTS invoice_line_insert $$$
remove that its already there on the top. – Abhik Chakraborty;
after the first statementDROP TRIGGER IF EXISTS invoice_line_insert ;
– Abhik Chakraborty