how to use variable in place of tablename

greenspun.com : LUSENET : SQL Server Database Administration : One Thread

sir, can i use variables in the select statement. if i want to create a variable & used in place of table name this will give me error.

please help me if i want to use variable in place of table name

declare @mvar varchar(50) select @mvar='Employee' select * from @mvar -- error shows @mvar not found ?????

-- Anonymous, September 19, 2001

Answers

Shyam,

Create a string that contains the Transact SQL statement that you want to execute, then use the EXEC statement to exectute it.

Good Luck,

Eric

-- Anonymous, September 20, 2001


Moderation questions? read the FAQ