|
How can we insert the dynamic query result into temporary table without defined the structure of that temporary table.
(comments are locked)
|
|
To generate a temporary table dynamically without specificng the structure up front, use the The datatypes will be determined by the base datatypes in the source tables (or expressions if an explicit convert is done)
(comments are locked)
|
|
When you say "dynamic query results", I assume you mean the results from a string containing sql, that you execute with EXECUTE('select * from someTable') If that's the case, you have only one option that I can think of: Use a global temporary table. Like this: Then you can use the global temporary table in your code. Like this: The problem with this solution is that the temporary table you create is global. It will cause problems in a multi-user environment, if this is run by two users at the (more or less) same time the SELECT INTO will fail since the table already exists.
(comments are locked)
|


I tried Something like that: insert into @table EXEC(@sql)
Without define the @table..how can solve this problem
See my answer. But please be aware of the global temporary table concurrency issues that I mention as well.