title: After Update Trigger to Maintain Badge Count
body: <p>I was wondering how I could accomplish something with a trigger on a table I have created?</p>
  <p>I have the following tables:
  ClientAccount
  ClientActivity</p>
  <p>In ClientAccount I have an attribute that is a count of the number of ClientActivity records that a Client has. I use that count as a Badge on a tab.</p>
  <p>Whenever a new activity is created the following trigger fires off:</p>
  <pre><code>SELECT ALL
  
  USE [officemgt]
  GO
  SET ANSI_NULLS ON
  GO
  SET QUOTED_IDENTIFIER ON
  GO
  
  ALTER TRIGGER [dbo].[RecountInsertedClientActivities] 
     ON  [dbo].[CLIENTACTIVITY]
     AFTER INSERT 
  AS 
  BEGIN
  
      SET NOCOUNT ON;
  
      UPDATE CLIENTACCOUNT
      SET Count_ClientActivitiesAsClient=(SELECT COUNT(*) FROM ClientActivity WHERE ClientActivity.parent_Client_RID=CLIENTACCOUNT.ID)
      FROM inserted
      LEFT JOIN CLIENTACCOUNT ON CLIENTACCOUNT.ID=inserted.parent_Client_RID
  
  END
  </code></pre>
  <p>I then have a similar trigger that fires off if a ClientActivity record is Deleted.</p>
  <p>These two triggers work just fine.</p>
  <p>The issue is that sometimes an activity may be changed from one client to another. So, I would need to update the counts for both the old client so it is reduced and then update the count for the new client the activity was assigned to.</p>
  <p>How can I do that?</p>