title: Dynamic Column Name in SQL in Update statement
body: <pre><code>DECLARE @sql NVARCHAR(max)
  DECLARE @ParmDefinition NVARCHAR(500)
  SET @sql = 'UPDATE [Table1] SET [Table1].[@columnName] = TEST';
  SET @ParmDefinition = N'@columnName NVARCHAR(50)';
  EXEC sp_executesql @sql, @ParmDefinition, @columnName = N'MyColumn';
  </code></pre>
  
  <p>When I run the above query, I get <code>Invalid column name '@columnName'.</code>. Clearly, the column name is not being replaced when the query is run.</p>
  
  <p>In reality, my @sql variable is much larger and I have many columns I wish to update, thus I would like to avoid doing <code>SET SQL =</code> for all enumerations of the column name.</p>
  
  <p>I'd like to declare the sql string once, and invoke the query with different values. e.g.:</p>
  
  <pre><code>EXEC sp_executesql @sql, @ParmDefinition, @columnName = N'MyColumn';
  EXEC sp_executesql @sql, @ParmDefinition, @columnName = N'AnotherColumn';
  EXEC sp_executesql @sql, @ParmDefinition, @columnName = N'YetAnotherColumn';
  -- And so on
  </code></pre>
  
  <p>Is something like this possible?</p>