I currently have a main stored procedure calling many stored procedures:
Main --|
--|
--| > Exec Pre-processing SP (create and populate #temp table)
--|
--| > Exec Actual update
--|
--| > Exec Post-Process (consume and drop #temp table)
The problem I’m currently having is that I need to grab the original values from the database, and the values being passed into the main stored procedure so that I can execute post processing to the update in the last step (stored procedure) being called.
I cannot change the stored procedure signatures or the main stored procedure.
When I try to execute this scenario, I get an invalid object in the post-processing stored procedure.
How can I pass my values from the first stored procedure to the last stored procedure.
You need to create the temp table higher up in the calling hierarchy than all the stored procs that consume it. Since you say you cannot alter
Main, the only chance to do this would be to create a new outermost procedure that creates#tempand then callsMain.You can then modify the pre- procedure to populate the already existing table. You shouldn’t need to explicitly drop the table anywhere.
Alternatively, you could create a permanent table, and include a spid column that indicates which connection data was inserted from. You’d also ensure that any selects/deletes against this table again use the
@@SPIDvalue. I posted this as an answer to Session-global temporary tables