title: T-SQL UPDATE using self join for a table variable
body: <p>Imagine there is a table:</p>
  
  <pre><code>declare @tab table (id int, val int)
  insert into @tab(id, val)
  values (1,10),(2,20),(1,15)
  </code></pre>
  
  <p>there is a need to update the table and set for every id the sum of all values with same ids in the table</p>
  
  <pre><code>update @tab
  set val = (select sum(val) from @tab tab where tab.id = id)
  </code></pre>
  
  <p>The where clause of the last query is always true and therefore the every row would contain the sum of all values in the table.</p>
  
  <p>If the table was real (not table variable) I would reference it using the table name:</p>
  
  <pre><code>update realtab
  set val = (select sum(val) from @tab tab where tab.id = realtab.id)
  </code></pre>
  
  <p>It is possible to make such an update for table variables?</p>