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.
Author |
Topic |
sedan76
Starting Member
2 Posts |
Posted - 2004-04-18 : 02:52:54
|
hello gurus,here is what i'm doing.. I want to create a temporary table as follows.EXECUTE('Select * into #temp1 from ' @tablename )When i execute this i get the following error.Invalid object '#temp1'. I tried to create with no # meaning just a ordinary table it is wroking. But i badly want to create temporary table. I guess this may be tiny question yet...could some one help me please.Thanks in advance. |
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2004-04-18 : 05:01:22
|
The error won't be coming from this statement but as soon as the statement completes the temp table will be dropped as the statement is run as a separate batch. Therefore the temp table will not be accessible by future statements.You can do this using openquery or openrowsetselect * into #a from openquery(...)but this will create a new connection with more problems probably.Another option is to create the temp table from the table structure - as you want to do this using a variable containg the table name you will have to get the structure from the system tables and use alter table to add columns to the temp table. The temp table will only then be available to nested batches (exec's or called SPs). Probably better to review what you are trying to do.seehttp://www.nigelrivett.net/AccessTempTablesAcrossSPs.html==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
|
|
|
|
|