title: Updating a COLUMN Based on a Field Value
body: <p>All, I have four columns (<code>A INT</code>, <code>B INT</code>, <code>C INT</code> and <code>D VARCHAR(1)</code>) in a table <code>TableName</code>. I want to move the values from column <code>C</code> to either <code>A</code> or <code>B</code> based upon the value in <code>D</code>. So if <code>D = 'A'</code> I want to move the value in <code>C</code> to <code>A</code>. How can I achieve this?</p>
  
  <pre><code>DECLARE @Column COLUMN;
  UPDATE TableName 
  SET (@Column = 
      (CASE 
          WHEN D = 'A' THEN A 
          WHEN D = 'B' THEN B
       END)) = C;
  </code></pre>
  
  <p><em>Note. I understand the above is madness, but I am trying to express the problem as clearly as possible. I have also exhausted my search for answers. I am not new to SQL but this one has me stumped. Any help is as always, most appreciated.</em></p>