title: Merge query output to existing table. New rows should be added and for duplicate rows column name flag should be increment
body: <p>Suppose I have table <code>a</code></p>
  
  <pre><code>id company flag
  1.  1001.    2
  2.  1002.    1
  3.  1003.    1
  </code></pre>
  
  <p>Want to merge below output to table <code>a</code></p>
  
  <pre><code>1. 1001.   1
  4. 1004.   1
  3. 1003.   1
  </code></pre>
  
  <p>Output should be</p>
  
  <pre><code>1.  1001.    3
  2.  1002.    1
  3.  1003.    2
  4.  1004.    1
  </code></pre>
  
  <p>Where <code>id</code> and <code>company</code> are same . Increment flag . Otherwise add new row. In SQL Server.</p>