简体   繁体   中英

Trigger with syntax error on if statement

Mysql won't allow me to create the following trigger due to syntax error, I think in the way I have written the if statement, can anyone help with what this should look like?

DELIMITTER $$
CREATE TRIGGER gl_bal_upd_update AFTER UPDATE ON journal_line
FOR EACH ROW
BEGIN
DECLARE curr varchar(10); 
DECLARE period varchar(10);

select period_name,currency 
into period,curr
from journal_header jh
where jh.journal_header_id = NEW.journal_header_id;   

INSERT IGNORE INTO general_ledger_balance (account_comb_id,period_name)values(NEW.account_comb_id,period);

UPDATE general_ledger_balance glb
SET glb.debit = IF(NEW.debit + glb.debit - OLD.debit - NEW.credit - glb.credit + OLD.credit > 0, NEW.debit + glb.debit - OLD.debit - NEW.credit - glb.credit + OLD.credit,0)(
,glb.credit = IF(NEW.credit + glb.credit - OLD.credit -NEW.debit - glb.debit + OLD.debit > 0, NEW.credit + glb.credit - OLD.credit - NEW.debit - glb.debit + OLD.debit,0)
,glb.currency = curr
WHERE glb.account_comb_id = NEW.account_comb_id
AND glb.period_name = period; 

END $$

DELIMITER ; 

You had delimiter spelled wrong, plus a left parenthesis randomly at the end of a line. Try this, it gets by syntax errors:

DELIMITER $$
CREATE TRIGGER gl_bal_upd_update AFTER UPDATE ON journal_line
FOR EACH ROW
BEGIN
DECLARE curr varchar(10); 
DECLARE period varchar(10);

select period_name,currency 
into period,curr
from journal_header jh
where jh.journal_header_id = NEW.journal_header_id;   

INSERT IGNORE INTO general_ledger_balance (account_comb_id,period_name)values(NEW.account_comb_id,period);

UPDATE general_ledger_balance glb
SET glb.debit = IF(NEW.debit + glb.debit - OLD.debit - NEW.credit - glb.credit + OLD.credit > 0, NEW.debit + glb.debit - OLD.debit - NEW.credit - glb.credit + OLD.credit,0)
,glb.credit = IF(NEW.credit + glb.credit - OLD.credit -NEW.debit - glb.debit + OLD.debit > 0, NEW.credit + glb.credit - OLD.credit - NEW.debit - glb.debit + OLD.debit,0)
,glb.currency = curr
WHERE glb.account_comb_id = NEW.account_comb_id
AND glb.period_name = period; 

END $$
DELIMITER ;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM