Avatar of tommym121
tommym121
Flag for Canada asked on

SQL - How to make table result available to the calling script

I have to execut this statement, it will return result as a table.  How can I make use of it
EXEC ('select ' + @columnsList + ',  '+ @SQLValuesSetTemplate + 'as ValueSet From ' + @sourceTable)
Microsoft SQL ServerMicrosoft SQL Server 2005Microsoft SQL Server 2008

Avatar of undefined
Last Comment
tommym121

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Saurabh Bhadauria

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
tommym121

ASKER
saurv

I try, I can not get it working. Would you be able to look at it what is missing?


DECLARE @str varchar(max)
Set @str=
'Select * from T1'
insert into #tempTable123
Exec (@str)
Print 'Hello' ;

Select * from #tempTable123

I got this error
Msg 208, Level 16, State 0, Line 5
Invalid object name '#tempTable123'.
tommym121

ASKER
Thanks
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy