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.
Printable View
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.
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)