
CREATE OR ALTER trigger tbreceita_icms_b02u for tbreceita_icms
active before update position 0
AS
DECLARE VARIABLE CODIGO VARCHAR(11);
BEGIN
   CODIGO = COALESCE((SELECT FIRST 1 A.CODIGO FROM TBRECEITA_ICMS A WHERE A.CODIGO = NEW.CODIGO AND A.ID <> NEW.ID),'');
   IF(CODIGO <> '') THEN
   BEGIN
         EXCEPTION "..." ' CODIGO:'||NEW.CODIGO||' JA CADASTRADO!';
   END
END

CREATE OR ALTER trigger tbreceita_icms_b02i for tbreceita_icms
active before insert position 1
AS
DECLARE VARIABLE CODIGO VARCHAR(11);
BEGIN
   CODIGO = COALESCE((SELECT FIRST 1 A.CODIGO FROM tbreceita_icms A WHERE A.CODIGO = NEW.CODIGO),'');
   IF(CODIGO <> '') THEN 
   BEGIN
         EXCEPTION "..." ' CODIGO:'||NEW.CODIGO||' JA CADASTRADO!';
   END
END


