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)
 Alter table

Author  Topic 

Richard Branson
Yak Posting Veteran

84 Posts

Posted - 2004-10-12 : 09:25:33
Hi - I'm picking up an error on the following query.

Server: Msg 170, Level 15, State 1, Line 21
Line 21: Incorrect syntax near '@table'.


For the following:

Declare @Table Varchar(50)


Create table #TempHort
(
Ent_nbr varchar(10) Not Null
)

Declare Tbl Cursor for

Select Description
from CL_Hort

Open Tbl
fetch Next from Tbl into
@Table

while @@fetch_status=0

Begin
Alter table #TempHort add @table char(50)

Fetch Next from Tbl into
@Table
End


Close Tbl
Deallocate Tbl


Help???

You can't teach an old mouse new clicks.

surefooted
Posting Yak Master

188 Posts

Posted - 2004-10-12 : 09:39:44
Use brackets around @table. '[@table]'

-Jon
Now a "Yak Posting Veteran".
Go to Top of Page

Richard Branson
Yak Posting Veteran

84 Posts

Posted - 2004-10-13 : 01:50:52
I tried that already and it didn't work.

You can't teach an old mouse new clicks.
Go to Top of Page

jen
Master Smack Fu Yak Hacker

4110 Posts

Posted - 2004-10-13 : 01:56:24

try this:
declare @sql nvarchar(1000) --place this outside the cursor fetch

set @sql='Alter table #TempHort add ' + @table + ' char(50)'
exec sp_executesql @sql



--------------------
keeping it simple...
Go to Top of Page

Richard Branson
Yak Posting Veteran

84 Posts

Posted - 2004-10-13 : 11:58:43
Thanks Jen.

You can't teach an old mouse new clicks.
Go to Top of Page
   

- Advertisement -