title: Update Using Case in SQL Server
body: <p>I have a scenario where I want to update multiple columns of first table from multiple rows of second table. But the case only updates from first row from second table. </p>
  
  <p>Any help to achieve this with out using cursor?</p>
  
  <pre><code>create table Table1 (ColA varchar(20), ColB varchar(20), ColC varchar(20))
  
  insert into Table1 values (1, null, null)
  
  create table Table2 (ColA varchar(20), ColB varchar(20), ColValue varchar(20))
  
  insert into Table2 values (1, 2, 'X'), (1, 3, 'Y')
  
  update Table1 
  set ColB = case 
                when T1.ColB = 2 
                   then T1.ColValue 
                   else T0.ColB 
             end,
      ColC = case 
                when T1.ColB = 3 
                   then T1.ColValue 
                   else T0.ColC 
             end
  from Table1 T0 
  inner join Table2 T1 on T0.ColA = T1.ColA
  
  select * from Table1
  </code></pre>
  
  <p>Looking at the result, the statement has updated only <code>ColB</code></p>