Pass tablename to stored procedure

I have a stored procedure called upsTest(see below).  I’d like to pass table name as a parameter, so I create another stored procedure called uspTest1, but it doesn’t work.  Is there any way I can use stored procedure to pass tablename?   Thanks in advance.

CREATE PROCEDURE uspTest  
AS
select * from table1


CREATE PROCEDURE uspTest1  
@TableName varchar(50)
AS
select * from @TableName
meimeiusAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
acampomaConnect With a Mentor Commented:

try this
declare @SQL Varchar(1000)
Set @SQL='select * from ' + @TableName
exec(@SQL)
0
 
meimeiusAuthor Commented:
Thank you very much!  Excellent!
0
All Courses

From novice to tech pro — start learning today.