Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 table as variable to SP

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2001-03-23 : 13:05:37
kridlet writes "Greetings Gurus,

I am attempting to use a stored procedure to create a recordset based on a table taken as a variable. I have read some of the dynamic SQL posts and FAQs, but have been unable to make this work. Any help will be greatly appreciated.

Here is the procedure:

CREATE PROCEDURE sp_TempTable
@inputTblName varchar(255)
AS

DECLARE @tmpStr varchar(300)

SET @tmpStr = 'SELECT * INTO #tmpTbl FROM ' + @inputTblName

EXEC (@tmpStr)

SELECT * FROM #tmpTbl

Everything works up to the last line, which returns the error:

Server: Msg 208, Level 16, State 1, Procedure sp_TempTable, Line 11
Invalid object name '#tmpTbl'.

Is there a way around this?"
   

- Advertisement -