I am using Sybase DB with TSQL.
I am trying to work between 2 SPROCS, one nested inside the other.
My outer SPROC will create a temp table #temp_table and fill it up with values to 200. Once the temp table has been populated with 200 entries, it will be used by the inner SPROC for a JOIN.
So essentially, my outer SPROC will have the following (simplified):
CREATE TABLE #temp_table
(
... columns ...
)
and my inner SPROC will have the following:
SELECT
SOME_COLUMNS
FROM
SOME_TABLE
INNER JOIN
#temp_table
ON
SOME_CONDITION
When I try to test this, I run the script for my inner SPROC and it complains of #temp_table not existing, and fails to create the SPROC in the DB. So when I try to go run my outer SPROC, it will also fail.
Could I please get some pointers on how to solve this problem?
Don’t do it in two stored procedures. Do it all in one. A single stored procedure can have as many SQL statements as you need to get the job done, and a temp table is only available within the context of the stored procedure where it’s created.