title: Sql Trigger After Insert Update another table with conditions
body: <p>I am creating After Insert trigger , its working fine, but I have certain conditions before executing the statements inside the trigger</p>
  
  <blockquote>
    <ol>
    <li>Based on Different CustomerId Run the trigger, I want check which CustomerId got inserted in my LoyaltyDetailsTable, say if last insert
    was Customerid=2 then pass that Customerid in where condition then run
    the trigger , or if Customerid = 1 then run the trigger for that Id,
    so on.</li>
    <li>I want to check whether in PriceClaimTable the inserted CustomerId exist  or not, If exists then update the details else just insert the
    values in LoyaltyDetailsTable only.</li>
    </ol>
  </blockquote>
  
  <p><strong>Trigger query</strong></p>
  
  <pre><code>CREATE TRIGGER DetailsAfterInsert ON [dbo].[LoyaltyDetailsTable]
  FOR INSERT
  
  as
  
  UPDATE PriceClaimTable 
  SET CurrentPoints = 
  (  
  (SELECT SUM(LoayaltyPointsTable.Points) AS RecentPoints FROM LoayaltyPointsTable
  join LoyaltyDetailsTable ON LoayaltyPointsTable.LoyaltyPointsId 
  = LoyaltyDetailsTable.LoyaltyPointsId
  WHERE CustomerId=1 and LoyaltyDetailsId= (SELECT MAX(LoyaltyDetailsId)  
  AS LoyaltyDetailsTable FROM LoyaltyDetailsTable))
  
  + 
  
  (SELECT CurrentPoints FROM PriceClaimTable WHERE ClaimCustomerId=1 and 
  PriceClaimId=(SELECT max(PriceClaimId) FROM PriceClaimTable
  ))
  
  ) 
  WHERE ClaimCustomerId=1 and PriceClaimId=(SELECT max(PriceClaimId) FROM PriceClaimTable)
  </code></pre>
  
  <p>This is my first attempt to write a trigger, and <a href="https://stackoverflow.com/questions/28432383/linq-update-a-row-if-new-rows-are-inserted-in-another-table">here</a> is table structure.</p>
  
  <p>Any help would be great.</p>