4
Guys, I have a Trigger in the FRM_46 table that would replicate the data right after the Insert or update to the FRM_31 table, however, it is not replicating, I already analyzed and made the tests, however, I could not verify where the error is.
ALTER TRIGGER [dbo].[TGR_FORMULARIO_REPLICAÇÃO_NOVO_PROCESSO_ESTRATEGICO]
ON [dbo].[FRM_46]
AFTER UPDATE, INSERT
AS
BEGIN
DECLARE
@TarefaID INT,
@DataDoPerfilCliente nVARCHAR(15),
@PerfilCliente nVARCHAR(15),
@ContaID INT
BEGIN
SELECT @TarefaID = F.TarefaID,
@DataDoPerfilCliente = CONVERT(DATE,GETDATE(),103),
@ContaID = t.UsuIDCliente,
@PerfilCliente = f.C33
FROM inserted F
INNER JOIN Tarefa T on t.TarID = f.ChamadoID
IF @ContaID NOT IN (SELECT ContaID FROM FRM_31)
INSERT INTO FRM_31 (ContaID, C01, C02, C05) VALUES (@ContaID, @DataDoPerfilCliente, @PerfilCliente, @TarefaID);
IF @ContaID IN (SELECT ContaID FROM FRM_31)
UPDATE FRM_31 SET C01 = @DataDoPerfilCliente, C02 = @PerfilCliente, C05 = @TarefaID, C08 = null WHERE ContaID = @ContaID
END
END
Initial suggestion: read the series "Traps in trigger procedure programming", published in https://social.technet.microsoft.com/wiki/pt-br/contents/articles/38010.armadilhas-na-programca-procedural
– José Diz
Put an example of
insert
that is not having the expected result, please– Sorack