title: Condition check in SQL Server trigger
body: <p>I have created a trigger to insert some values into <code>T2</code> based on what has been inserted into <code>T1</code>. This is used to audit how long a process is taken by monitoring the value of the <code>Status</code> and a date diff in a report between two different status values. </p>
  
  <p>I am missing where to include the condition if the <code>i.IdNumber</code> and <code>i.status</code> exist in the <code>tblEX1StatusChangeLog</code> table that do not do anything.  </p>
  
  <p>Any help would be much appreciated, and thanks in advance. </p>
  
  <p>My issue is if the related object is modified in anyway I see duplicate status values and IdNumber where they should only be unique status for each of the ID numbers. I know I can massage the data in the report to provide desired results even with the duplicates however I want to minimize the data going into the changelog table. </p>
  
  <pre><code>create trigger trgEx1StatusChange 
  on tblEx1 
  after update, insert    
  as 
  begin
      insert into tblEx1StatusChangeLog (IdNumber, UpdatedOn, Status, updatedby)
          select i.IdNumber, GETDATE(), i.Status, SUSER_NAME()
          from tblQuotes as t
          inner join inserted as i on t.IdNumber = i.IdNumber
  end 
  </code></pre>
  
  <p>I would like to see these results </p>
  
  <pre><code>IdNumber   UpdatedOn    Status    UpdatedBy
  ----------------------------------------------
  100001     04102019     Open      domain/user
  100001     04132019     Closed    domain/user
  </code></pre>
  
  <p>Not</p>
  
  <pre><code>IdNumber   UpdatedOn    Status    UpdatedBy
  ----------------------------------------------
  100001     04102019     Open      domain/user
  100001     04102019     Open      domain/user (if the object related to idNumber-100001 is edited but status is not changed)
  100001     04132019     Closed    domain/user
  </code></pre>