title: SQL update rows in column using CASE statement
body: <p>I have two tables, Users and #TempTable (which is a subset of Users). I would like to update a column, IsActive, in the Users table. I would like to set IsActive = 1 if a user that is in #TempTable is also in the Users table, and set IsActive = 0 otherwise.</p>
  
  <p>Getting the users from Users that are NOT in #TempTable (IsActive should be set to 0 for these users):</p>
  
  <pre><code>-- (Users \ #TempTable) U (#TempTable \ Users)
  SELECT  u.UserName
  FROM    Users u 
  WHERE   (u.UserName) NOT IN 
      (SELECT t.[User Name] FROM #TempTable t) 
  UNION ALL 
  SELECT  t.[User Name] 
  FROM    #TempTable t
  WHERE   (t.[User Name]) NOT IN 
      (SELECT u.UserName FROM Users u)
  </code></pre>
  
  <p>Let's call this the ResultSet. I would appreciate some help with my UPDATE statement. What I'd like to be able to do is:</p>
  
  <pre><code>UPDATE Users
  SET IsActive = (CASE WHEN User.UserName IN ResultSet THEN 0 ELSE 1 END) 
  </code></pre>
  
  <p>without having to write out the CASE WHEN for each User.UserName. Thanks in advance!</p>