tgoglia
asked on
Table Names as Parameters for Stored Procedures
How do I pass a table name as a parameter to a stored procedure? When I use variables passed as parameters in most contexts, I have no problem(i.e. Select * from Titles Where L_Name Like @lastName). But I can't find a way to use variables in the 'From' clause(i.e. Select * from @tableName).
I've been able to build Sql strings and execute them using the 'exec' command, but with this approach I'm unable to use the results of the dynamically executed query in the continuation of my stored procedure.
I've been able to build Sql strings and execute them using the 'exec' command, but with this approach I'm unable to use the results of the dynamically executed query in the continuation of my stored procedure.
Short answer: EXEC is the only way. You can't do something like
SELECT * FROM @table_name (i wish it were possible)
Yet, you CAN get results from EXEC. That's just nontrivial.
BTW, i wouldn't call it an easy question ...
SELECT * FROM @table_name (i wish it were possible)
Yet, you CAN get results from EXEC. That's just nontrivial.
BTW, i wouldn't call it an easy question ...
Short answer: EXEC is the only way. You can't do something like
SELECT * FROM @table_name (i wish it were possible)
Yet, you CAN get results from EXEC. That's just nontrivial.
BTW, i wouldn't call it an easy question ...
SELECT * FROM @table_name (i wish it were possible)
Yet, you CAN get results from EXEC. That's just nontrivial.
BTW, i wouldn't call it an easy question ...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for the help. I was thinking of that as a possible solution, but it seemed like such a complicated solution to a problem that I thought was simple. I'm new to the bulletin board/newsgroup thing, so sorry if I underrated my question. Is there a remedy?
Never mind :)
I would have answered it even if it was only 10 points ...
Besides, it didn't take much time to answer it :)
I would have answered it even if it was only 10 points ...
Besides, it didn't take much time to answer it :)
ASKER