title: T SQL merge example needed to help comprehension
body: <p>The following:</p>
  
  <pre><code>MERGE dbo.commissions_history AS target
  USING (SELECT @amount, @requestID) AS source (amount, request)
  ON (target.request = source.request)
  WHEN MATCHED THEN
      UPDATE SET amount = source.amount
  WHEN NOT MATCHED THEN
      INSERT (request, amount)
      VALUES (source.request, source.amount);
  </code></pre>
  
  <p>from <a href="https://stackoverflow.com/a/2967983/857994">https://stackoverflow.com/a/2967983/857994</a> is a pretty nifty way to do insert/update (and delete with some added work).  I'm finding it hard to follow though even after some googling.</p>
  
  <p>Can someone please:</p>
  
  <ul>
  <li>explain this a little in simple terms - the MSDN documentation mutilated my brain in this case.</li>
  <li>show me how it could be modified so the user can type in values for amount &amp; request instead of having them selected from another database location?</li>
  </ul>
  
  <p>Basically, I'd like to use this to insert/update from a C# app with information taken from XML files I'm getting.  So, I need to understand how I can formulate a query manually to get my parsed data into the database with this mechanism.</p>