home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / database / sybase / 710 < prev    next >
Encoding:
Text File  |  1993-01-21  |  2.0 KB  |  60 lines

  1. Newsgroups: comp.databases.sybase
  2. Path: sparky!uunet!news.gtech.com!caw
  3. From: caw@gtech.com (Christopher A. White)
  4. Subject: Stored Procedures and temp tables
  5. Message-ID: <1993Jan21.182032.23975@gtech.com>
  6. Keywords: lock
  7. Sender: news@gtech.com (USENET Administrator)
  8. Organization: GTECH Corporation, West Greenwich, RI
  9. References: <wolfgang.727637656@sfu.ca>
  10. Date: Thu, 21 Jan 1993 18:20:32 GMT
  11. Lines: 47
  12.  
  13. [ I don't know if any of you have had a hard time figuring out
  14. how to do this, but we did for some reason, so I figured I post
  15. a copy of my internal note. If you didn't already know this,
  16. it can save you a lot of code and make things easier.]
  17.  
  18. Here is a little programming tidbit: #temp tables created in a
  19. stored procedure are visible to stored procedures call by the
  20. creator. So, if procedure a creates #techs and then calls 
  21. procedure b, b can use, access, update, etc. #techs.
  22.  
  23. The problem we've always had is that the called procedure (b,
  24. in this example) could not be created. However, I have come
  25. up with a way to do so. It requires adding some code to the
  26. procedure creation script [our scripts have a section at the top
  27. that drops the procedure if it already exists, then the creation
  28. script itself. Since they are isql scripts, each section is
  29. terminated with a "go"].
  30.  
  31. Since we know what proc b exepects to be in the temp table,
  32. we can put the temp table creation clauses in the section
  33. between the drop procedure and the create procedure, like this:
  34.  
  35. If exists (select * from sysobjects ... etc
  36.    drop procedure b
  37. go
  38.  
  39. select * into #techs from techs where 1 = 2
  40. go
  41.  
  42. create table #display as (disp_line   char(80) )
  43. go
  44.  
  45. create procedure b as
  46. .
  47. .
  48. .
  49. go
  50.  
  51. The #temp tables must be the SAME in both procedures (a and b).
  52.  
  53.  
  54. Topher
  55. -- 
  56.  Christopher A. White                    | Free Radical Programming
  57.  caw@gtech.com                           |   High combat Rock'n'Roll 
  58.  GTech Corporation, West Greenwich, RI   |      Software - Break the rules
  59.  The opinions expressed are mine alone   |         and take no prisoners!
  60.