Use of EXEC , string and INTO....

Hi,
I've got a query wich is execute with EXEC.
I need to do this:

@QUERY = select col1 as C1,col2 as C2,col3 as C3 from TABLE

exec(@QUERY)

insert into TABLE2 values(C1,C2,C3)

////////////////////////////////////////////////
I need in fact to insert in TABLE2 the result of the query.

Thanks for your help .
bruno_boccaraAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Aneesh RetnakaranDatabase AdministratorCommented:
Hello bruno_boccara,

insert into TABLE2
exec(@QUERY)





Aneesh R
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ee_rleeCommented:
try this

@QUERY = insert into TABLE2 (C1,C2,C3)  select col1,col2,col3 from TABLE
exec(@QUERY)
0
bruno_boccaraAuthor Commented:
Thanks you....
0
Greg BessoIT Solutions EngineerCommented:
ee rlee, just saw your post here and it helped me get something done I was spending all morning on. I hate being a newb with T-SQL, but it's nice to finally get through problems.

Thx!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.