home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / database / 7930 < prev    next >
Encoding:
Internet Message Format  |  1992-11-18  |  3.3 KB

  1. Xref: sparky comp.databases:7930 comp.databases.sybase:347
  2. Path: sparky!uunet!stanford.edu!bcm!mparsons
  3. From: mparsons@fleming.csc.bcm.tmc.edu (Mark Parsons)
  4. Newsgroups: comp.databases,comp.databases.sybase
  5. Subject: Re: help needed on sybase stored procedure
  6. Date: 18 Nov 1992 15:54:59 GMT
  7. Organization: Baylor College of Medicine, Houston, Tx
  8. Lines: 83
  9. Distribution: world
  10. Message-ID: <1edp0jINN18v@gazette.bcm.tmc.edu>
  11. References: <1992Nov14.000317.58320@ssf-corp.dhl.com> <steven.722080875@rupee>
  12. Reply-To: mparsons@fleming.csc.bcm.tmc.edu (Mark Parsons)
  13. NNTP-Posting-Host: fleming.csc.bcm.tmc.edu
  14. Originator: mparsons@fleming.csc.bcm.tmc.edu
  15.  
  16.  
  17. In article <steven.722080875@rupee>, steven@dev.state.COM.AU (Steven Sweeting) writes:
  18. |> julies@ssf-corp.dhl.com (Julie Stephens) writes:
  19. |> 
  20. |> >I'm attempting to create a generic Sybase stored procedure which will
  21. |> >accept up to 254 input parameters.  Within the stored procedure
  22. |> >I would like to determine how many parameters were passed to the
  23. |> >stored procedure & process them.  To accomplish this, I'd like to
  24. |> >have a loop which creates input parm names on the fly & retrieve 
  25. |> >the values stored in those input parameters. Can this be done?
  26. |> 
  27. |> >Here is an example of what I'm trying to do.  The problem here is
  28. |> >clear (see WHILE clause).  The program will evaluate the temporary
  29. |> >variable @argName--not the input parameter @arg1. 
  30. |> 
  31. |> >    CREATE PROC processArguments
  32. |> >        @arg1    varchar(255),
  33. |> >        @arg2    varchar(255),
  34. |> >        @arg3    varchar(255),
  35. |> >        ...
  36. |> >        @arg254 varchar(255)
  37. |> >    AS
  38. |> >    DECLARE @argName varchar(30)
  39. |> >    DECLARE @argInt  int
  40. |> 
  41. |> >    ProcessArguments:
  42. |> >    SELECT @argInt = 1
  43. |> >    SELECT @argName = '@arg1'
  44. |> 
  45. |> >    WHILE @argName IS NOT NULL
  46. |> >      BEGIN
  47. |> >        (blah, blah, blah)
  48. |> >        SELECT @argInt = @argInt + 1
  49. |> >        SELECT @argName = '@arg' + (SELECT CONVERT(char(3), @argInt))
  50. |> >      END
  51.  
  52.  
  53. The suggestion on the recursive call got me thinking . . . . 
  54. Are you going to do similar processing, i.e., is the "(blah,
  55. blah, blah)" the same?, or can you determine which processing to
  56. do based on the actual *value* of the arg's?  Will the processing
  57. of the args be independent of each other?
  58.  
  59. If so . . and I know this isn't as slick as we'd all like . . but
  60. hopefully a little easier to write and debug than the recursive
  61. call(no offense!! ;-) . . . 
  62.  
  63. Redefine your first proc like such:
  64.  
  65. CREATE PROC processArguments
  66.     @arg1    varchar(255) = NULL,    /* default to NULL if not supplied */
  67.     ...
  68.     @arg244    varchar(255) = NULL
  69. AS
  70.     exec processArguments2 @arg1
  71.     ...
  72.     exec processArguments2 @arg254
  73. RETURN
  74.  
  75. Now define the second process:
  76.  
  77. CREATE PROC processArguments2
  78.     @arg1    varchar(255)
  79. AS
  80.     if @arg1 is not NULL    /* or whatever series of tests you need? */
  81.     begin
  82.         blah, blah, blah
  83.     end
  84. RETURN
  85.  
  86. Of course, you could go straight to processArguments2 from your front
  87. end . . but you'd have to do 254 calls whereas using the two level
  88. method above would require only one front-end-to-server call.  The
  89. calls between the processes within the server will take up much less
  90. overhead than doing separate calls to the server(from the front-end)
  91. for each possible variable.
  92.  
  93. Sybase isn't going to allow indirect variable processing . . . so this
  94. is the . . .um . . 'cleanest' idea I can come up with . . . 
  95.  
  96. Other suggestions?
  97.  
  98. Mark
  99.