title: Updating one column based on the value of another column #2
body: <p>Have a table (settings) with 1000+ rows, and two columns (name, value). I need to update a handful of values, based on the name.</p>
  
  <p>Using <a href="https://stackoverflow.com/questions/32102348/updating-one-column-based-on-the-value-of-another-column">Updating one column based on the value of another column</a> I get "Invalid Column Name 'AppName' and AppID'". </p>
  
  <pre><code>update Test.dbo.Setting
  set Value = (CASE 
                 WHEN Name = AppName
                   THEN 'Test1'
                 WHEN Name = AppID
                   THEN 'Test2'
                 END);
  </code></pre>
  
  <p>Why would this work in the other thread, but not in my example? In any case I moved on to wrap the AppName and AppID in single quotes.</p>
  
  <pre><code>update Test.dbo.Setting
  set Value = (CASE 
                 WHEN Name = 'AppName'
                   THEN 'Test1'
                 WHEN Name = 'AppID'
                   THEN 'Test2'
                 END);
  </code></pre>
  
  <p>Which comes back with "Cannot insert the value NULL into column 'Value', table 'Test.dbo.Config'; column does not allow nulls. UPDATE fails." Which is true, it doesn't allow NULLs, and my thought is that because there is no ELSE statement it's trying to write NULL to the rest of the 1k+ values.</p>
  
  <p>So lets try it with else..</p>
  
  <pre><code>update Test.dbo.Setting
  set Value = (CASE 
                 WHEN Name = 'AppName'
                   THEN 'Test1'
                 WHEN Name = 'AppID'
                   THEN 'Test2'
                 ELSE Value
                 END);
  </code></pre>
  
  <p>Oops, it works, but also overwrites all Values to what they currently are.. so while it "works" I do not want to touch the other values other than the ones I specify..</p>
  
  <p>Aside from a complete mess of what to try next.. any better ideas on how to optimize?</p>
  
  <p>Thanks.</p>