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)
 Using variable for table name

Author  Topic 

phishCoder
Starting Member

4 Posts

Posted - 2006-09-27 : 13:01:38
Executing the included query gives the following error:
"Msg 137, Level 15, State 2, Line 9
Must declare the variable '@imailTable'."

Replacing the @imailTable with dbo.ilivewell_net executes without error.

Thanks in advance for your help.

Jason


declare @imailTable varchar(30)
declare @userid varchar(30)
declare @PW2 varchar(31)

set @imailTable = 'dbo.ilivewell_net'
set @userid = 'deleteme'

select @PW2 = password
from @imailTable
where userid = @userid

DonAtWork
Master Smack Fu Yak Hacker

2167 Posts

Posted - 2006-09-27 : 13:02:34
Look up Dynamic Sql.
Or, do not use a table name as a variable. no real reason for it.

[Signature]For fast help, follow this link:
http://weblogs.sqlteam.com/brettk/archive/2005/05/25.aspx
Learn SQL
http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-09-27 : 21:01:05

http://www.sommarskog.se/dynamic_sql.html


Madhivanan

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

- Advertisement -