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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Table Name as Variable

Status
Not open for further replies.

stevenk140

Programmer
Nov 20, 2003
34
CA
How come this will not work?

DECLARE @TableName VARCHAR(40)
SET @TableName = 'analog'
SELECT * FROM @TableName

Server: Msg 137, Level 15, State 2, Line 5
Must declare the variable '@TableName'.


How could I get around this?
 
declare @sql varchar(1000)
select @sql = 'select * from ' + @TableName
exec (@sql)


======================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top