Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7976911
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T09:02:34+00:00 2026-06-04T09:02:34+00:00

Is it possible to pass the table name as input parameter to the stored

  • 0

Is it possible to pass the table name as input parameter to the stored procedure?

For example:

create procedure test
@tablename char(10)
as
begin
select * from @tablename
end
go

I know this does not work. So what is the best way if I want to pass the table name into the stored procedure?

Many thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T09:02:35+00:00Added an answer on June 4, 2026 at 9:02 am

    The safest way to do this is via a view.

    Create a view which unions all the tables you may wish to access (and which must all have the same column structure), and prefix the rows with the table name.

    CREATE VIEW MultiTable
    AS
        SELECT 'table1' AS TableName, * FROM table1
        UNION ALL
        SELECT 'table2' AS TableName, * FROM table2
        UNION ALL
        SELECT 'table3' AS TableName, * FROM table3
    

    Your stored procedure can now filter on the table name:

    CREATE PROCEDURE test
        @TableName varchar(100)
    AS
        SELECT * FROM MultiTable WHERE TableName = @TableName
    

    This is safer than using dynamic SQL creation and execution.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to pass a table as a parameter to a stored procedure. Is
Is it possible to pass parameters to a catch block? Here is some example
Is it possible to pass a input value of prompt box like this? <script
I need to pass an array of strings as parameter to a MySQL stored
I have a stored procedure that I would like to pass a string to,
I'd like to pass a table as a parameter into a scaler UDF. I'd
The following code errors: <cfdbinfo datasource=#Application.DSN# name=getCols type=columns table=#this.tableName#> <cftry> <cfquery name=getColumnDetails dbtype=query> SELECT
Is it possible to pass a parameter into a CTE that selects a node
Please look at this query. select name form table Let suppose this returns 100
Possible Duplicate: Pass a data.frame column name to a function I am trying to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.