I have return stored procedure
create procedure t1
Declare @tablename varchar(1000)
As
Begin
Declare @result varchar(50), @t1 varchar(60)
Set @result = 'select * from' + @tablename
Exec(@result)
set @t1 = (select * into #temp from @result)
I am stuck how to pass @result
variable to @t1
inside the stored procedure.
I wanted to pass @result
output to another SQL query
2条答案
按热度按时间0tdrvxhp1#
Perhaps the following will help with what you are trying to do.
Create your temp table first then insert into it as part of your dynamic statement.
If you create the temp table within the dynamic SQL it won't be accessible outside of its execution scope.
r3i60tvu2#
The temp table structure is not fixed it will vary as per different tablename.wanted to create temp table dynamically