title: T-SQL: Update column only if value is provided
body: <p>Currently I have this <code>UPDATE</code> statement:</p>
  
  <pre><code>UPDATE Customer 
  SET Name = @Name,
      Age = @Age,
      Email = @Email
      ...
  </code></pre>
  
  <p>Now I need to include column into the <code>UPDATE</code> statement only if value is provided. Otherwise, do not include the column in the <code>UPDATE</code> statement. </p>
  
  <p>So conceptually probably something like this:</p>
  
  <pre><code>UPDATE Customer 
  SET
      IF LEN(@Name) &gt; 0 THEN Name = @Name,
      IF LEN(@Age) &gt; 0 THEN Age = @Age,
      IF LEN(@Email ) &gt; 0 THEN Email = @Email
      ...
  </code></pre>
  
  <p>Is there any way can achieve this? I'm thinking about dynamic query but the list of update columns are super long, so tons of work need to be done to change to dynamic query like this:</p>
  
  <pre><code>SET @SQL = 'UPDATE Customer SET '
  
  IF LEN(@Name) &gt; 0
      SET @SQL = @SQL + 'Name = @Name,'
  
  IF LEN(@Age) &gt; 0
      SET @SQL = @SQL + 'Age= @Age,'
  </code></pre>