2012-09-18 9 views
6
delimiter $$ 
CREATE TRIGGER REDUCE_NOTE_COUNT 
AFTER DELETE ON iv_notes 
FOR EACH ROW BEGIN 
DECLARE supplierid int(11); 
DECLARE customerid int(11); 

SELECT supplierid ,customerid FROM iv_documents WHERE id=OLD.note_documentid; 
SET supplierid=supplierid; 
SET customerid=customerid; 

IF supplierid=OLD.note_companyid THEN 
    update iv_documents 
      set supplier_notes=supplier_notes-1 
      where id=OLD.note_documentid and supplier_notes>0; 
END IF; 
IF customerid=OLD.note_companyid THEN 
    update iv_documents set customer_notes=customer_notes-1 
      where id=OLD.note_documentid 
      and customer_notes>0 ; 
END IF; 
END$$ 
delimitatore

;non è consentito restituire un set di risultati da un trigger mysql

+2

nuovo suggerimento: per favore, la gente, CHIEDI la domanda, non è ovvio cosa stai chiedendo. Includi la versione che usi e possibilmente un messaggio di errore :) –

risposta

20

Non è possibile eseguire istruzioni SELECT dal trigger. Se si desidera impostare le variabili, quindi utilizzare la dichiarazione SELECT INTO, ad es. -

DECLARE supplierid_ INT(11); 
DECLARE customerid_ INT(11); 

SELECT 
    supplierid, customerid 
INTO 
    supplierid_, customerid_ 
FROM 
    iv_documents 
WHERE 
    id = OLD.note_documentid; 

IF supplierid_ = OLD.note_companyid THEN 
... 

Inoltre, rinominare le variabili, devono differire dai nomi dei campi.

+0

thank you.it funziona – Tarika

+0

Accetta la risposta se è OK. – Devart

Problemi correlati