|
|
Question : variable tablename ?
|
|
I execute a stored procedure out of VB4. In this stored procedure there is a SELECT FROM statement. The problem is that I wanna use the sp to select from different tables. So there is my question:
Can I supply the tablename as a varible? for example:
sp_get @tablename char(25)
SELECT * FROM @tablename
|
Answer : variable tablename ?
|
|
No you can't use a parameter for the table name. A stored procedure is compiled to present an optimized query plan, based upon the tables involved and the columns access/filtered.
The best you can do is to create multiple differently named stored procedures (name them based upon table target table name), and then use a variable name to substitute the procedure name that works with the table you desire at run time.
|
|
|
|