title: SQL partial update of columns based on case statement?
body: <p>Recently I have had to do a few variable updates to a table, and although I am aware of the MERGE statement (although need to catch up on all of that!), I also performed the following statement to optional update a table and wish to check if this is "a good idea" or has some hidden consequences that I not aware of.</p>
  
  <p>So in my case, I pass a primary key to a table, however depending on if parameters passed are null or not, I update the column.. obviously if you had to ensure a forceful update (of a status etc.) then you would just update the column.. this is to save having multiple "IF / THEN" type structures..</p>
  
  <pre><code>create procedure sp_myprocedure
  as
     @id                     bigint,
     @field1                 int = null,
     @field2                 varchar(255) = null,
     @field3                 char(1) = null
  begin 
  
     update my_table
     set 
        field1 = case when @field1 is not null then @field1 else field1 end,
        field2 = case when @field2 is not null then @field2 else field2 end,
        field3 = case when @field3 is not null then @field3 else field3 end,
     where
        id = @id
  
  end
  </code></pre>
  
  <p>Just after some thoughts of the above or is it best to pursue the MERGE statement for scenarios like the above?</p>
  
  <p>Many thanks in advance, </p>