title: Using temp table with exec @sql in stored procedure
body: <p>I have a stored procedure and part of them as below:
  @DRange is a incoming varchar value</p>
  
  <pre><code>declare @sql varchar(max)
  set @sql = 'select * into #tmpA from TableA where create_date &gt;= getDate - ' + @DRange + '' and is_enabled = 1'
  
  exec (@sql)
  
  select * from #tmpA
  </code></pre>
  
  <p>The problem is when I execute the stored procedure, an error message occurs:
  Cannot find the object "#tmpA" because it does not exist or you do not have permissions.</p>
  
  <p>Is it not possible to use temp table and execute it or did I do something wrong?</p>