-2
Good Afternoon,
I have a table that contains the id_document (int) AI fields, username and nosso_numero(int). I would like to use a Trigger if it is possible that after I insert a new document the field our number would receive the field id_formatted document type LPAD(id_document, 8, '0'). I would like a help to develop this visa Trigger q are inserted several documents at a time in a single action. From now on I appreciate any help.
I’ve tried to
If nosso_numero is null then
UPDATE tb_documentos_emitidos SET nosso_numero = LPAD(id_documento, 8, '0')
WHERE tb_documentos.nosso_numero = null ;
end if
Now I’ve tried
CREATE
DEFINER=`root`@`localhost`
TRIGGER `amoruna`.`tgr_nossonumero`
BEFORE INSERT ON `amoruna`.`tb_documentos_emitidos`
FOR EACH ROW
If (NEW.nosso_numero IS NULL) THEN
SET NEW.nosso_numero = (LPAD(NEW.id_documentos, 8, '0'));
end if
Works if I enter the value manually from the id_documents field.
But the field is auto-incremented and if it is set the regisro automatically does not work.
puts what you’ve tried
– Tmilitino
puts in old question. any information that can help answer your question has that is there
– Tmilitino