Solved

is it possible to parameterise a table name

Posted on 2008-10-06
1
207 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
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
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 Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

803 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