Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 need help with temporary tables in sql server.

Author  Topic 

Malli123
Starting Member

2 Posts

Posted - 2010-12-08 : 15:09:01
I have a problem where in I have to create a temporary table in stored proc and use the same temp table's data in other stored proc in SQL server. But I want to those stored procs seperately not as nested stored proc in sql server. As I understand, local temp tables would only be available to the session which created it.Is there a way I can run the second stored proc in the same session as previous one so that I am able to access temporary table's data in 2nd stored proc in sql server. Please help !!

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2010-12-08 : 15:14:15
You can use a gloabl temporary table (##table). Or a regular table. But it would be interesting to see what you're doing as this may not be the best way at all.
Go to Top of Page

Malli123
Starting Member

2 Posts

Posted - 2010-12-08 : 17:23:43
Thanks Russell for your such a quick reply. I have a table with following data

Code : this could repeat
type : there would be different predefined types for each code
desc : string of chars (message block )
code 2 : unique for each column (this is not be shown in the o/p as this is system generated)

Code type description code2 (unique column)
123 abc 10
123 i ghf 19
123 r uyg 21
123 f ihj 34
124 pqr 35
124 r hgb 23
124 i uij 36
123 jhy 67
123 i uyt 89
123 r wty 45
125 oiu 46
125 i okj 68
125 r oiu 12

first stored proc would take input parameter as (Code as 123 for eg)
show the o/p as
Code desc
123 abc
123 jhy

second procedure would take input from the above o/p i.e (Row selected,type) depending on the type entered, would that type details
for eg ( 1 for first row and i for type)
o/p
code type desc
123 i uyt

but then if two different users are executing the two procedures simultaneously , the o/p shouldn't mix with each other and should be different based on what they got o/p in first proc.





Go to Top of Page

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2010-12-08 : 19:18:45
Can't this be combined into one Stored Procedure that takes two parameters?
Go to Top of Page
   

- Advertisement -