Results 1 to 2 of 2

Thread: Passing table name into Stored Procedure

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2001
    Location
    Vietnam
    Posts
    613

    Passing table name into Stored Procedure

    How to pass the name of the table as a parameter into a store procedure so that the Select statement can be run from this table?

    Thanks.

  2. #2
    PowerPoster BruceG's Avatar
    Join Date
    May 2000
    Location
    New Jersey (USA)
    Posts
    2,657
    Assuming SQL Server, your SP would look something like this:
    Code:
    CREATE PROCEDURE dynamic_select @table_name varchar(30) AS
    
    DECLARE @sel_string varchar(30)
    
    SET @sel_string = "SELECT whatever FROM " 
                              + @table_name + " WHERE whatever"
    
    EXECUTE (@sel_string)
    "It's cold gin time again ..."

    Check out my website here.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width