Problem solve Get help with specific problems with your technologies, process and projects.

Calling another stored procedure's temp table

I am trying to create a stored procedure that will have a temporary table inside. Because I will need to be running recursive in the stored procedure, I have created another stored procedure that will call first stored procedure's temp table. But I failed to compile my second stored procedure because it always appears that the table cannot be found. Can you provide some information on how to call another stored procedure's temp table on execution?

The #table created by the first stored procedure needs to exist before the second stored procedure calling it can be created. Actually it is a rule that all the #tables referenced in a stored procedure must exist at the time of creating the stored procedure otherwise the stored procedure will not be created. This is irrespective of which stored procedure creates the #table initially.

The best practice is for you to create these objects in sequence in the same session as follows:

create #<TABLE_NAME> (...)
create procedure <PROC1> AS ...
create procedurte <PROC2> AS ...
Please note that the #table must exist before either PROC1 or PROC2 can be created. It is also a good practice to ensure that PROC1 exists before PROC2 is created; otherwise you will get a warning.

Dig Deeper on Linux servers

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.