Solved

is it possible to parameterise a table name

Posted on 2008-10-06
1
208 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 …
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

839 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