Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I pass a table name to a stored procedure

Status
Not open for further replies.

bigfoot

Programmer
May 4, 1999
1,779
0
0
US
I have a general procedure that i'd like to ass a table name to. It would kinda look like the following (6.5 & 7.0)<br>
<br>
CREATE PROCEDURE sp_mything (<br>
@tablename varchar(100)<br>
) as<br>
select * from @tablename where ....<br>
<br>
<br>
How can I get this to work????<br>
<br>

 
<br>
Try using EXEC...<br>
<br>
declare @MyTable varchar (50)<br>
SELECT @MyTable = "sysObjects"<br>
<br>
EXEC ("SELECT * FROM " + @MyTable)<br>
<br>
Seán.<br>
<br>

 
WOW!!! Thanks so much! I've been looking for this for a while.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top