Creation of Temporary tables in T-sql

I would like to know whether I should create temporary tables in the main procedure or in the called procedure, and please state your reasons why.
LVL 1
countrymeisterAsked:
Who is Participating?
 
BrandonGalderisiCommented:
Then the main proc is where it needs to be created in order for the data to be shared.
0
 
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
Please state your programming needs, as that will dicate the use or not use of temporary tables, and not whatever I believe.
0
 
BrandonGalderisiCommented:
The scope of a temp table can only go down, not up.  So if you think you might need the data in the calling procedure, create it there.  It can be referenced and populated by any procedure in the procedure call stack at that point.
0
 
countrymeisterAuthor Commented:
jimhorn

I have a main procedure which gathers data from the database and makes call to  another four procedures. In one of those four procedures I need to load data into a temporary table which is then used further down by another two procedures for calculatioion and data manipulation.

All the execs for the four procs are done from the main proc.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.