title: Merge, delete when not on Source
body: <p>I have an issue with a merge statement into a FACT TABLE</p>
  
  <p>It was pretty simple until the users started to delete records from the source.</p>
  
  <p>Current SQL:</p>
  
  <pre><code>Set Count = 1
  WHEN NOT MATCHED
     INSERT
  WHEN MATCHED
   UPDATED
  </code></pre>
  
  <p>New SQL:</p>
  
  <p>So in this example, a record has been deleted from the source, it no longer matches but there is nothing to insert.  I would like it the count to be set to 0.</p>
  
  <pre><code>WHEN DELETED FROM SOURCE
  Set Count = 0
  </code></pre>
  
  <p>.</p>
  
  <pre><code>Source
  Bob Jones |  1111 
  Mary Jones |  1112 
  James Jones |  1113 
  Helen Jones |  1114
  
  TARGET
  Bob Jones |  1111 | Count 1
  Mary Jones |  1112| Count 1
  James Jones |  1113| Count 1
  Helen Jones | | 1114| Count 1
  Peter Market |  1115| Count 0 
  </code></pre>
  
  <p>I’m loading to a fact table using a merge and now they are just blanket deleting records, my facts are off.  This must be accounted for somehow?</p>
  
  <p>Thank you for any help at all.</p>