title: Implementing IF Condition Within a T-SQL UPDATE Statement
body: <p>Using T-SQL, I would like to execute an UPDATE statement that will SET columns only if the corresponding variables are defined.</p>
  
  <p>Here's a simple pseudo-tsql example of what I'm trying to accomplish:</p>
  
  <hr>
  
  <pre><code>--Declaring vars
  @ID int,
  @Name nvarchar(20),
  @Password nvarchar(10)
  
  --Run the update
  UPDATE User
  SET
  IF LEN(@NAME) &gt; 0
    Name = @Name,
  IF LEN(@Password) &gt; 0
    Password = @Password
  </code></pre>
  
  <hr>
  
  <p>From what I can tell by reading how IF conditions work in T-SQL, in order to accomplish the same result as the above pseudo code, I would have to create an UPDATE statement for every IF condition - which is what I'm trying to avoid having to do.</p>
  
  <p>Is it possible to dynamically SET fields/columns based on a condition using only one UPDATE statement? - If so, how?</p>