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
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Its Shows invalid Object Name For temp table

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2006-01-13 : 08:45:59
GunaSekaran.P writes "You can Just Run this below script in sql 2000

By Giving any table Name

I am inserting into to the table #tt but i coudnt ablt to select
from the table
Note I am not using any Create table Statement for creating of table

Can i know how i can do this , if this is not possible let me know the reason.

declare @st varchar(2000)
declare @strSql nvarchar(2000)
set @st='select * '
set @strSql= @st +'into #tt from tablename'
print @strSql
Exec sp_Executesql @strSql
select * from #tt
drop table #tt
"

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-01-13 : 09:05:24
it is out of scope. Change to use global temp table ##tt

-----------------
'KH'

if you can't beat them, have someone else to beat them
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-01-13 : 09:05:35
It losts its scope after Exec statement
You need to use them in the same block

set @st='select * '
set @strSql= @st +'into #tt from tablename
select * from #tt'
print @strSql
Exec sp_Executesql @strSql

Why are you using Dynamic SQL?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -