I have a problem with my Trigger sql, which is always set the id_tingkatan to 4 no matter what I do, having checking the nomor_reference to set the id to 5 is still not working
BEGIN
-- Check if the new value of id_tingkatan_wewenang is NULL
IF NEW.id_tingkatan_wewenang IS NULL THEN
SET NEW.id_tingkatan_wewenang = 2;
END IF;
IF NEW.nomor_reference is NOT NULL THEN
SET NEW.id_tingkatan_wewenang = 5;
END IF;
-- Check if tgl_keluar_verifikator is NOT NULL and catatan_verifikator is NULL
IF NEW.tgl_keluar_verifikator IS NOT NULL THEN
SET NEW.id_tingkatan_wewenang = 4;
ELSEIF OLD.tgl_keluar_verifikator IS NOT NULL AND OLD.catatan_verifikator IS NOT NULL THEN
SET NEW.id_tingkatan_wewenang=3;
ELSEIF NEW.tgl_keluar_verifikator IS NOT NULL AND
NEW.catatan_verifikator IS NOT NULL THEN
SET NEW.id_tingkatan_wewenang=1;
ELSE
-- Check if the new value of id_jumlah_total_tagihan is 1
IF NEW.id_jumlah_total_tagihan = 1 THEN
SET NEW.id_tingkatan_wewenang = 3;
ELSE
SET NEW.id_tingkatan_wewenang = 5;
END IF;
-- Check status K3
IF NEW.id_status_k3 = 1 THEN
SET NEW.id_tingkatan_wewenang = 3;
ELSEIF NEW.id_status_k3 = 2 THEN
SET NEW.id_tingkatan_wewenang = 1;
END IF;
END IF;
-- Final fallback (if necessary)
IF NEW.id_tingkatan_wewenang IS NULL THEN
SET NEW.id_tingkatan_wewenang = 2;
END IF;
END
What I do is literally make the priority like make the if condition of nomor_reference is not null on top and bottom and it still not work, and make the double params like if nomor_reference is not null and … it still not working and still updating the value of id_tingkatan_wewenang to 4
What I’m expecting is make when the nomor_reference is not null update the id to 5
Mr Brama is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.