Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 dynamic query into temp table

Author  Topic 

sent_sara
Constraint Violating Yak Guru

377 Posts

Posted - 2011-01-11 : 08:54:53
Hi ,
I need to store the dynamic query into temp table(#temp).but iam not able to,could you help me correcting the below query?




select * into #temp
Exec(@sql)

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2011-01-11 : 09:12:07
#temp must already exist. Create it first.

INSERT INTO #temp
EXEC(@sql)

Jim

Everyday I learn something that somebody else already knew
Go to Top of Page

sent_sara
Constraint Violating Yak Guru

377 Posts

Posted - 2011-01-11 : 09:28:10
I DONT know the column name explicitly..
column name varies dynamically

quote:
Originally posted by jimf

#temp must already exist. Create it first.

INSERT INTO #temp
EXEC(@sql)

Jim

Everyday I learn something that somebody else already knew

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-01-11 : 10:43:15
use second method below

http://sqlblogcasts.com/blogs/madhivanan/archive/2007/11/26/select-columns-from-exec-procedure-name-is-this-possible.aspx

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -