CREATE OR ALTER trigger ttbestoque_cliente_b01iu for tbestoque_cliente
active before insert or update position 1
AS
DECLARE VARIABLE ID VARCHAR(100);
BEGIN
    FOR
        SELECT
           ID

        FROM TBESTOQUE_CLIENTE T
        WHERE T.EMPRESA_ID = NEW.EMPRESA_ID
        AND T.ID <> NEW.ID

    INTO
    :ID
    DO BEGIN
        EXCEPTION "..." 'CLIENTE: '||'<b>'||COALESCE((SELECT FIRST 1 C.RAZAOSOCIAL FROM TBEMPRESA C WHERE C.CODIGO = NEW.EMPRESA_ID), '')||'</b>'||' COM REGISTRO DE ESTOQUE JÁ VINCULADO';
    END

END;
