Charles, so I understood it is not to allow inclusion of rows in the FLAN table when the value of the CODTDO column is "00017431".
When building trigger procedures it is necessary to be aware that they are triggered to handle one or more lines, or even none. At first I recommend reading the series of articles "Traps in trigger procedure programming”.
Because the trigger procedure can receive more than one line in the same event, if it is to reject one or more lines, then the whole block is rejected.
Here is code with initial suggestion, which can be improved.
-- código #1
CREATE TRIGGER dbo.noInsertTeste
on dbo.FLAN
instead of INSERT as
begin
-- verifica número de linhas a tratar
declare @NL int;
set @NL= (SELECT count(*) from (SELECT top (2) * from INSERTED) as I);
-- encerra o processamento se não há linha para tratar
IF @NL = 0 return;
-- rejeita bloco se houver alguma linha com o código específico
IF exists (SELECT * from INSERTED where CODTDO = '00017431')
begin
PRINT 'Lançamentos não gerados pois o Responsavel TESTE não pode ser gerado lançamento.'; -- raiserror?
ROLLBACK TRANSACTION;
return;
end;
-- inclui as linhas na tabela FLAN
INSERT on dbo.FLAN
SELECT * from INSERTED;
end;
go
I did not have the opportunity to test the code; it may contain error(s).