I have a stored procedure and part of them as below: @DRange is a incoming varchar value
declare @sql varchar(max)
set @sql = 'select * into #tmpA from TableA where create_date >= getDate - ' + @DRange + '' and is_enabled = 1'
exec (@sql)
select * from #tmpA
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.
Is it not possible to use temp table and execute it or did I do something wrong?
See Question&Answers more detail:os