Solved

is it possible to parameterise a table name

Posted on 2008-10-06
1
206 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
1 Comment
 
LVL 32

Accepted Solution

by:
Daniel Wilson earned 500 total points
Comment Utility
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

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

Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

763 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

10 Experts available now in Live!

Get 1:1 Help Now