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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

stored procedure using a dynamic table name

Status
Not open for further replies.

bbolte

Programmer
Joined
Sep 30, 2002
Messages
113
Location
US
i need to bring in the name of a temp table that is dynamically named. do i do that any different from a normal parameter?
 
You set up the parameter in the same way but you can't just substitute it into the FROM clause. You need to use dynamic SQL:

Code:
CREATE PROC myproc
  @tbl varchar(30)
AS

DECLARE @sql varchar(200)

SET @sql = 'SELECT col1, col2 FROM ' + @tbl

EXEC(@sql)
GO

--James
 
thanks. just found the faq as well about this: faq183-3132. i probably should have done a search first. thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top