title: Trigger Only Work Once/Debug
body: <p>I created a trigger to, when a record is inserted or updated in a table T1, he mirror this in a table T2 (following some conditions).</p>
  
  <p>In the first statement (insert) in T1, the triggers works well (copy everything in T1 to T2). But after the first, the trigger won't run anymore (using Insert or update clause). </p>
  
  <p>Code:</p>
  
  <pre><code>ALTER TRIGGER [dbo].[Replicacao]
     ON  [dbo].[ImportacaoXML]
     AFTER UPDATE, INSERT
  AS 
  BEGIN
      IF EXISTS (SELECT ProgramacaoBarcas.ViagemID, ProgramacaoBarcas.Data 
                 FROM ProgramacaoBarcas, inserted 
                 WHERE ProgramacaoBarcas.ViagemID = inserted.ViagemID 
                   AND ProgramacaoBarcas.Data = inserted.Data)        
      BEGIN 
        UPDATE ProgramacaoBarcas 
        SET ViagemID = inserted.ViagemID, Data = inserted.Data, 
            Extra = inserted.Extra, Modalidade = inserted.Modalidade,
            FleetID = inserted.FleetID, Partida = inserted.Partida, 
            Chegada = inserted.Chegada, Capacidade = inserted.Capacidade, 
            LocationID = inserted.LocationID, DestinoID = inserted.DestinoID, 
            CodLinha = inserted.CodLinha
        FROM inserted 
        WHERE ProgramacaoBarcas.ViagemID = inserted.ViagemID 
          AND ProgramacaoBarcas.Data = inserted.Data 
          AND ProgramacaoBarcas.Bloqueada = 0
      END
      ELSE
      BEGIN
        INSERT INTO ProgramacaoBarcas (ViagemID, Data, Extra, Modalidade, FleetID, Partida, Chegada, Capacidade, LocationID, DestinoID, CodLinha, Bloqueada)
           SELECT 
               ViagemID, Data, Extra, Modalidade, FleetID, Partida, Chegada, 
               Capacidade, LocationID, DestinoID, CodLinha, 0 
           FROM inserted      
      END 
  END
  </code></pre>
  
  <p>Anyone have any clue ? I searched to logs, but found nothing. Is there any way to debug a trigger ?</p>
  
  <p>(Newbie here, please be patient)</p>
  
  <p><strong>Obs:</strong> I found the solution. The code is correct now.</p>