Click here to Skip to main content
15,921,716 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all:

I opened a session to MS SQl. I did not terminate it until the end in c#.net.

First I called a stored procedure that creates a temporay table #xxxx. After processing some data for updating, I then called another stored procedure that uses the table table #xxxx created in the first stored procedure. But in the second procedure I am getting the error that says #xxxx not found.

Why am I getting such as error. According to the known rule, the temporary table in MS SQL is supposed to exist through out the session.

Thanks!
Posted

1 solution

There are two types of temporary table in MS SQL
one is Local temporary table and other one is Global temporary table.
#xxxx is the local temporary table which can be accessed in the same stored procedure in which you are creating them. To use in different stored procedures use Global temporary table.
You can create them like ##xxxx.
This table exists till you have connection the the database. Once you disconnect the table will be dropped.
 
Share this answer
 
Comments
tryharder 21-Nov-11 15:55pm    
This global temp. table with ## is really global. It means other sessions can see it too. I need a temp. table which is to my session only and can be used in different stored procedures in a session. ( not real global temp. table)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900