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

  1. Xref: sparky comp.databases:7877 comp.databases.sybase:324
  2. Path: sparky!uunet!think.com!ames!sun-barr!cs.utexas.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: 16 Nov 1992 15:35:25 GMT
  7. Organization: Baylor College of Medicine, Houston, Tx
  8. Lines: 53
  9. Distribution: world
  10. Message-ID: <1e8f3tINN1ii@gazette.bcm.tmc.edu>
  11. References: <1992Nov14.000317.58320@ssf-corp.dhl.com>
  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 <1992Nov14.000317.58320@ssf-corp.dhl.com>, julies@ssf-corp.dhl.com (Julie Stephens) writes:
  18. |> I'm attempting to create a generic Sybase stored procedure which will
  19. |> accept up to 254 input parameters.  Within the stored procedure
  20. |> I would like to determine how many parameters were passed to the
  21. |> stored procedure & process them.  To accomplish this, I'd like to
  22. |> have a loop which creates input parm names on the fly & retrieve 
  23. |> the values stored in those input parameters. Can this be done?
  24. |> 
  25. |> Here is an example of what I'm trying to do.  The problem here is
  26. |> clear (see WHILE clause).  The program will evaluate the temporary
  27. |> variable @argName--not the input parameter @arg1. 
  28. |> 
  29. |>     CREATE PROC processArguments
  30. |>         @arg1    varchar(255),
  31. |>         @arg2    varchar(255),
  32. |>         @arg3    varchar(255),
  33. |>         ...
  34. |>         @arg254 varchar(255)
  35. |>     AS
  36. |>     DECLARE @argName varchar(30)
  37. |>     DECLARE @argInt  int
  38. |> 
  39. |>     ProcessArguments:
  40. |>     SELECT @argInt = 1
  41. |>     SELECT @argName = '@arg1'
  42. |> 
  43. |>     WHILE @argName IS NOT NULL
  44. |>       BEGIN
  45. |>         (blah, blah, blah)
  46. |>         SELECT @argInt = @argInt + 1
  47. |>         SELECT @argName = '@arg' + (SELECT CONVERT(char(3), @argInt))
  48. |>       END
  49. |> 
  50.  
  51. From what I've seen(and played with) you cannot do indirect addressing
  52. or dynamic creation of code within a stored procedure . . at least not
  53. in Sybase(can you in other DB servers?).
  54.  
  55. Each time through the loop @argName will be set to a string that looks
  56. like 'arg??'.  In addition to that, the system will run indefinitely
  57. since @argName will never be set to NULL, i.e., this is an endless
  58. loop . . . unless you put in a test that says "If @argInt > 254 select
  59. @argNmae = NULL". 
  60.  
  61. If you use a different language, or move this to the front-end, 
  62. say . . . APT . . . you could do something like this . . but not in
  63. the server . . . 
  64.  
  65. Anyone reported this to Sybase as a feature enhancement request?
  66.  
  67. Mark
  68.  
  69.