?
Solved

is it possible to parameterise a table name

Posted on 2008-10-06
1
Medium Priority
?
212 Views
Last Modified: 2012-05-05
hi.

this may be a silly question but i'l ask it anyway.

is there anyway of being able to patameterise a table name?

so for instance pass the param @TableName into a stored proc and for example do:
select * from @TableName?
0
Comment
Question by:scm0sml
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 32

Accepted Solution

by:
Daniel Wilson earned 2000 total points
ID: 22653113
Short answer: No.

Long Answer: yes, but you must use dynamic SQL, thereby losing most of the benefits of a stored procedure.

Create Procedure dbo.MyProcedure
  @TabLename nvarchar(100)
AS
Declare @SQL nvarchar(200)
Set @SQL = "Select * from " + @TableName

Exec (@SQL)
0

Featured Post

Get MongoDB database support online, now!

At Percona’s web store you can order your MongoDB database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card. Handle your MongoDB database support now!

Question has a verified solution.

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

PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

777 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