Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL temp table creation help

Status
Not open for further replies.

s2001

Programmer
Dec 7, 2001
132
US
I am getting error when i run the following sql query:

Declare @tempTable varchar(50)
select @tempTable= '#' + @userName
DROP TABLE @tempTable

Error:
Server: Msg 170, Level 15, State 1, Line 3
Line 3: Incorrect syntax near '@tempTable'.

TIA

Thanks,
MB
 
The reason that Denis's code works while your doesn't is that SQL Server doesn't allow object names to be variables.

Denny
MCSA (2003) / MCDBA (SQL 2000)
MCTS (SQL 2005 / Microsoft Windows SharePoint Services 3.0: Configuration / Microsoft Office SharePoint Server 2007: Configuration)
MCITP Database Administrator (SQL 2005) / Database Developer (SQL 2005)

--Anything is possible. All it takes is a little research. (Me)
[noevil]
 
Thanks denis. Can we do it without using the exec command?
Becuase i have create table, insert into and select statement on the the temp table following the drop command.

TIA

Thanks,
MB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top