dimanche 6 septembre 2015

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 ;

Aucun commentaire:

Enregistrer un commentaire