Solved

Pass tablename to stored procedure

Posted on 2002-03-25
2
630 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Performance is the key factor for any successful data integration project, knowing the type of transformation that you’re using is the first step on optimizing the SSIS flow performance, by utilizing the correct transformation or the design alternat…
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 …
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

760 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now