I have created a trigger to collect an entered value, relate it to another table and change it. That value can be quite peculiar, so I look for it in two fields and also concatenating it:
create or replace TRIGGER "INTER_AGENTE"
BEFORE INSERT OR UPDATE
ON intercambios
REFERENCING NEW AS NEW
FOR EACH ROW
BEGIN
SELECT ag_nombre INTO :NEW.int_vendedor
FROM agentes
WHERE ag_denominacion like concat(:NEW.int_vendedor,'%')
or :NEW.int_vendedor like concat(ag_nombre, '%');
This works correctly in all cases except one, which I get error because it finds matches in two records, in different fields.
Find a value that looks like ag_name in ag_name="CASE1", but it also finds a value that resembles it in ag_name and then introduces ag_name="CASE2".
It occurs to me to give preferences, that is, if it finds a match with ag_denomination so that it stays with that. If you do not find anything, look in ag_name.
How do you see it? Is it possible?