user2696868
user2696868

Reputation: 5

Dynamic query results into temp table

I would like to play with the results of my dynamic query executable with

 execute sp_executesql @query; [it has many columns dependable on variables]

how can i export this into #temptable?

Upvotes: 0

Views: 374

Answers (1)

suff trek
suff trek

Reputation: 39767

You can't, unless you know in advance number/type of the columns. If you do (e.g. based on variables) you can create the temp table first and then do

INSERT INTO #TempTable
EXECUTE ...

Another possibility (not recommended) do a SELECT INTO ##GlobalTempTable.. inside of your dynamic SQL, this way the table will be accessible to outside scope.

Upvotes: 1

Related Questions