title: In SQL Server, how do I create a reference variable to a table?
body: <p>I'm currently using sp_executesql to execute a T-SQL statement with a dynamic table name. However, it is really ugly to see something like: </p>
  
  <pre><code>set @sql = 'UPDATE '+Table_Name+' SET ... WHERE '+someVar+' = ... AND '+someVar2' = ...'
  sp_executesql @sql
  </code></pre>
  
  <p>What I would rather like to have is a TABLE variable of which is a reference to a table, so I could do for example:</p>
  
  <pre><code>UPDATE TableRef SET ... WHERE ...
  </code></pre>
  
  <p>Because when I have really long T-SQL statements it gets really hard to read due to the format of it within a string.</p>
  
  <p>Any suggestions would be helpful.</p>