title: Query with dynamic table name
body: <p>I would like to change a dynamic SQL statement in a parametrized statement, but in the query the table name is dynamic. So I tried to paramrtrize the whole statement in this way, as I saw in the newCRMsupport's answer in <a href="https://social.msdn.microsoft.com/Forums/en-US/a84ac0aa-3870-4852-851e-0722fd476042/pass-a-tablename-as-a-parameter-in-adonet?forum=adodotnetdataproviders" rel="nofollow noreferrer">this link</a>:</p>
  
  <pre><code>command.CommandType = CommandType.Text;
  
  string sqlStr = " DECLARE @sqlSubstr nvarchar(max) SET @sqlSubstr = N'UPDATE quotename(@tempTable) = SET @flag = 1 WHERE @tempCol = @tempColVal' EXECUTE sp_executesql @sqlSubstr";
  command.CommandText = sqlStr;
  command.Parameters.AddWithValue("@tempTable", TemporaryTableName);
  command.Parameters.AddWithValue("@flag", flagToUpdate);
  command.Parameters.AddWithValue("@tempCol", ImportRegister.TemporaryTableKeyColumn);
  command.Parameters.AddWithValue("@tempColVal", sourceRow[ImportRegister.TemporaryTableKeyColumn]);
  command.ExecuteNonQuery();
  </code></pre>
  
  <p>But when I run it, I have an Exception. "Must declare calar variable @tempTable", and I can't figure out what I am missing.
  Thanks</p>