Is the creation of your table a simple select (or union of selects)?
If so you could use a derived table (which is often more efficient too).
In brief syntax is
SELECT ... FROM
[table1]
INNER (or whatever) JOIN
(SELECT ... FROM {ie this should be what is in your proc 1}) as 'derived_table_name'
ON derived_table_name.column_name1 = table1.column_name ...
WHERE ...
If you have any aggregate/calculated columns that you refer to you will need to give them a name so you can refer to them in the query.
Unless you have a good reason for wanting to use a temporary table.
1. create #table in Proc A
2. Create #table in Proc B before create procedure statement to take care of compilation
3. During executation time, you have access to #table created in Proc A.
Thanks to everyone, I used vechalapu's suggestoin ... it worked without step 2. Step 2 returned an error but without it I could still access the table previously created in ProcA
Arrowhouse, I missed your post. Thanks for your suggestion, but my subquery is way too complex (involves a lot of logical decisions) and I needed a procedure to evaluate some stuff.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.