Oct 1, 2003 #1 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?
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?
Oct 1, 2003 #2 JamesLean Programmer Joined Dec 13, 2002 Messages 3,059 Location GB 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 Upvote 0 Downvote
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
Oct 1, 2003 Thread starter #3 bbolte Programmer Joined Sep 30, 2002 Messages 113 Location US thanks. just found the faq as well about this: faq183-3132. i probably should have done a search first. thanks again. Upvote 0 Downvote
thanks. just found the faq as well about this: faq183-3132. i probably should have done a search first. thanks again.