title: How to reference a temporary table in a subquery?
body: <p>I have a local table variable in a stored procedure, containing a couple of columns; I need to update column 2 of each row with the result of a subquery based on the value of column 1 for that row.</p>
  
  <p>Something like:</p>
  
  <pre><code>UPDATE @mytable
  SET column2 = (SELECT ... FROM ... WHERE something = @mytable.column1)
  </code></pre>
  
  <p>But this doesn't seem to work, I get an error about @mytable being undefined.</p>
  
  <p>What is the correct syntax for this query?</p>