Solved

Pass tablename to stored procedure

Posted on 2002-03-25
2
640 Views
Last Modified: 2012-08-13
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
0
Comment
Question by:meimeius
2 Comments
 
LVL 6

Accepted Solution

by:
acampoma earned 50 total points
ID: 6894917

try this
declare @SQL Varchar(1000)
Set @SQL='select * from ' + @TableName
exec(@SQL)
0
 

Author Comment

by:meimeius
ID: 6895125
Thank you very much!  Excellent!
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question