title: How to use table variable in a dynamic sql statement?
body: <p>In my stored procedure I declared two table variables on top of my procedure. Now I am trying to use that table variable within a dynamic sql statement but I get this error at the time of execution of that procedure. I am using Sql Server 2008.</p>
  
  <p>This is how my query looks like, </p>
  
  <pre><code>set @col_name =  'Assoc_Item_' 
                + Convert(nvarchar(2), @curr_row1);
  
  set @sqlstat = 'update @RelPro set ' 
               + @col_name 
               + ' = (Select relsku From @TSku Where tid = ' 
               + Convert(nvarchar(2), @curr_row1) + ') Where RowID = ' 
               + Convert(nvarchar(2), @curr_row);
  
  Exec(@sqlstat);
  </code></pre>
  
  <p>And I get the following errors, </p>
  
  <p>Must declare the table variable "@RelPro".
  Must declare the table variable "@TSku".</p>
  
  <p>I have tried to take the table outside of the string block of dynamic query but to no avail.</p>