dynamically creating the #temp table and then used to insert the data

Posted by praveen on Stack Overflow See other posts from Stack Overflow or by praveen
Published on 2010-03-30T03:35:38Z Indexed on 2010/03/30 3:43 UTC
Read the original article Hit count: 404

Filed under:
|

Hi All,

I am importing an intermediate result of query into a temp table for further use, so I used a #temp table to maintain the same schema as

select * into # temp from schema.tableName where 1<>1;

insert into # temp from exec(table)

While I am doing this statement as a variable to pass the different tableName its not working

SET @TEMPSCHEMA = 'SELECT * INTO #temp FROM ' + @PKSchema + '.dbo.' + @PKTableName + ' WHERE 1<>1;'

exec(@TEMPSCHEMA)

INSERT INTO #temp

EXEC ( @SELECTSTATEMENT

)

however after exec statement it is not taking the values to the temp table.

it is showing the invalid object id #temp

© Stack Overflow or respective owner

Related posts about sql

Related posts about sql-server-2008