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
 Transact-SQL (2000)
 temp table error

Author  Topic 

harshal_in
Aged Yak Warrior

633 Posts

Posted - 2003-09-25 : 02:10:31
hi,
I have the following code:
....
.....
set @sql='create table #choice (cid int identity(1,1),Uid int,'+@c1+' int,'+@c2+' int,'+@c3+' int)'
print @sql
exec sp_executesql @sql
set @insert ='insert into #choice (uid,'+convert(varchar(10),@c1)+')
select uid ,oid from answermaster where qid='+convert(varchar(10),@c1)
print @insert
exec sp_executesql @insert
select * from #choice

....

it gives me an error as:
Invalid object name '#choice'.

any views?
thankyou.
harshal.

The Judgement of the Judge is as good as the Judge.

Amethystium
Aged Yak Warrior

701 Posts

Posted - 2003-09-25 : 06:41:10
You need to make it a global temporary table.

use ##choice instead of #choice.

__________________
Make love not war!
Go to Top of Page

Page47
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2003-09-25 : 07:16:41
Amethystium ... maybe. While a global temp table will solve the scope issue for this particular piece of code, it will also open up some contention issues when he has multiple simultanious users.

harshal, why do you care what the columns are named in a temp table? I'd recommend building your temp table without the dynamic SQL and alias column names as necessary in any rowsets returned to the user.

Jay White
{0}
Go to Top of Page

harshal_in
Aged Yak Warrior

633 Posts

Posted - 2003-09-25 : 11:38:26
quote:
Originally posted by Page47

Amethystium ... maybe. While a global temp table will solve the scope issue for this particular piece of code, it will also open up some contention issues when he has multiple simultanious users.

harshal, why do you care what the columns are named in a temp table? I'd recommend building your temp table without the dynamic SQL and alias column names as necessary in any rowsets returned to the user.

Jay White
{0}


I see what you are saying about the global temp tables.

the column names are the rows in some other table,I have to compare these values and formulate the result so I was planning to use the temp tables.

The Judgement of the Judge is as good as the Judge.
Go to Top of Page
   

- Advertisement -