• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2774
  • Last Modified:

Stored Procedure with 2 input and 1 output variable

I have a stored procedure that has 3 parameters.
2 of them are input parameters and the other is an output.
The strored procedure name is reconstruct, the parameters are @processed, @reconst, @reconstructed. @reconstructed is the output.
I would like to know the sql syntax or procedures in order to give @processed and @reconst values, execute the SP and retrieve the outputed value from @reconstructed.

Thanks in advanced.
0
nplib
Asked:
nplib
  • 6
  • 3
  • 2
1 Solution
 
bretCommented:
create procedure reconstruct @processed int, @reconst int, @reconstructed int
output
as
select @reconstructed = @processed + @reconst
go

declare @myvariable int

execute reconstruct 1, 2, @reconstructed = @myvariable output

select @myvariable
go
0
 
nplibAuthor Commented:
All though I got the result I was looking for I get a bunch of weird stuff in front of it first.

I ran this query

declare @mytemp varchar(255)
execute reconstruct 'ROGERS NANCY R', 'I.I', @reconstructed = @mytemp output
select @mytemp
go

and got this result

Warnings: --->
   W (1): 010P4: An output parameter was received and ignored.
   W (2): 010P4: An output parameter was received and ignored.
          <---

 1 record(s) affected


 1 record(s) affected


 1 record(s) affected


 1 record(s) affected


 1 record(s) affected


 1 record(s) affected


 1 record(s) affected


 1 record(s) affected


 1 record(s) affected


 1 record(s) affected


 1 record(s) affected


 1 record(s) affected


 1 record(s) affected


 1 record(s) affected


 1 record(s) affected


 1 record(s) affected


 1 record(s) affected


 1 record(s) affected


 1 record(s) affected


 1 record(s) affected


 1 record(s) affected

 column1        
 ---------------
 ROGERS NANCY R.

 1 record(s) selected [Fetch MetaData: 0/ms] [Fetch Data: 0/ms]

 [Executed: 07/07/06 12:42:41 EDT PM ] [Execution: 0/ms]

how do I supress or not get the above warnings, the column1 Rogers Nancy R. is correct.

but I get all those warning, so when I try to execute it from PHP it terminates.
0
 
bretCommented:
I think you can get rid of the "record(s) affected" lines by adding

set nocount on

at the beginning of the stored procedure.

As for the "output parameter ignored" - what does your parameter declaration
part of the procedure look like?  (i.e. everything from "create procedure" to "as ..."

0
How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

 
nplibAuthor Commented:
Here it is, but I wasn't the one who created it.
 create proc reconstruct
   (@processed varchar(255),
    @reconst   varchar(255),
    @reconstructed varchar(255) output)
 as
   declare @reconst_pos    int,
           @processed_pos  int,
           @reconst_len    int,
           @processed_len  int,
           @achar          char(1),
           @before_char    char(1),
           @before_num     int,
           @after_char     char(1),
           @after_num      int
    /* set positional variables */
      select @reconst_pos = 1
      select @processed_pos = 0
    /* calculate length of processed and reconst columns */
      select @reconst_len = datalength(@reconst)
      select @processed_len = datalength(@processed)
      select @reconstructed = @processed
    /* start checking the reconst data one char at a time */
    while @reconst_pos < @reconst_len
      begin
    /* next character */
        select @reconst_pos = @reconst_pos + 1
    /* set current, previous and next characters (used in most reconst calculations)
    */
        select @achar = substring(@reconst,@reconst_pos,1)
        select @before_char = substring(@reconst,@reconst_pos-1,1)
        select @before_num  = ascii(@before_char)
        select @after_char  = substring(@reconst,@reconst_pos+1,1)
        select @after_num   = ascii(@after_char)
    /* start checking for the action characters I, M, R, 2, P, E, D */
    /* insert one character */
        if @achar = "I"
           begin
             select @reconstructed =   substring(@reconstructed, 1, @before_num - 1)
                                     + @after_char
                                     + substring(@reconstructed, @before_num, 255)
          /* increment position in reconst to jump past characters we have just used */
             select @reconst_pos = @reconst_pos + 2
             continue
           end
    /* insert many characters */
        if @achar = "M"
          begin
            select @reconstructed =   substring(@reconstructed, 1, @before_num - 1)
                                    + substring(substring(@reconst, @reconst_pos + 2, @after_num) + space(@after_num), 1, @after_num)
                                    + substring(@reconstructed, @before_num, 255)
         /* increment position in reconst to jump past characters we have just used */
            select @reconst_pos = @reconst_pos + 2 + @after_num
            continue
          end
    /* Replace */
        if @achar = "R"
          begin
            if @after_char is NULL
              select @after_char = " "
            select @reconstructed =   substring(@reconstructed, 1, @before_num - 1)
                                    + @after_char
                                    + substring(@reconstructed, @before_num + 1, 255)
         /* increment position in reconst to jump past characters we have just used */
            select @reconst_pos = @reconst_pos + 2
            continue
          end
    /* replace 2 */
        if @achar = "2"
          begin
            if @after_char = NULL
              select @after_char = " "
            select @reconstructed =   substring(@reconstructed, 1, @before_num - 1)
                                    + @after_char
                                    + substring(@reconstructed, @before_num + 2, 255)
         /* increment position in reconst to jump past characters we have just used */
            select @reconst_pos = @reconst_pos + 2
            continue
          end
    /* ReplacePair */
        if @achar = "P"
          begin
            select @reconstructed =   substring(@reconstructed, 1, @before_num - 1)
                                    + substring(substring(@reconst, @reconst_pos+1, 2) + "  ", 1, 2)
                                    + substring(@reconstructed, @before_num + 1, 255)
         /* increment position in reconst to jump past characters we have just used */
            select @reconst_pos = @reconst_pos + 3
            continue
          end
    /* delete */
        if @achar = "E"
          begin
            select @reconstructed =   substring(@reconstructed, 1, @before_num - 1)
                                    + substring(@reconstructed, @before_num + 1, 255)
         /* increment position in reconst to jump past characters we have just used */
            select @reconst_pos = @reconst_pos + 1
            continue
          end
    /* delete many */
        if @achar = "D"
          begin
            select @reconstructed =   substring(@reconstructed, 1, @before_num - 1)
                                    + substring(@reconstructed, @before_num + @after_num, 255)
         /* increment position in reconst to jump past characters we have just used */
            select @reconst_pos = @reconst_pos + 2
            continue
          end
    /* Clobber */
        if @achar = "C"
          begin
            select @reconstructed =   substring(@reconstructed, 1, @before_num - 1)
                                    + substring(@reconst, @reconst_pos+1, 255)
         /* increment position in reconst to jump past characters we have just used */
            select @reconst_pos = @reconst_len
            continue
          end
    /* end of while loop */
    end
 return
0
 
grant300Commented:
Try running it again only do NOT reassign the output parameter in the execute statement...

BEGIN
declare @reconstructed varchar(255)
execute reconstruct 'ROGERS NANCY R', '', @reconstructed output
select @reconstructed
END
go

Ignore my apparent change to the middle argument; it came through with special characters which screwed up the editing.

BTW, this kind of character manipulation is really better done in a Java UDF (User Defined Function).  I don't know what version of Sybase ASE you are running or if you have the Java Option licensed, but if it is available, it will do the job faster and has the added advantage that it can be used as an inline function inside other SQL statements.

Bill
0
 
nplibAuthor Commented:
still get same warning messages
0
 
nplibAuthor Commented:
I don't know if I do or not, but asume that I do, I'll try anything now.
0
 
grant300Commented:
What was the stuff you are putting in the second argument???

It occurs to me that if it will screw up an editor, it might well be a problem for Sybase to swallow.
If you are trying to pass anything other than printable ASCII, you are asking for trouble.

Try it again without and put something benign in the middle argument.  That is, no NULLs, etc.

If that works, ultimately you will have to rework the code to get rid of the funky stuff from the @reconst argument.

I would suggest using something like \255  or some similar escape method.

Bill
0
 
nplibAuthor Commented:
It's complicated to explain.
But I will try,

The database was designed by a company called SirsiDynix. The have a stored procedure that takes a Title like Nancy R. Rogers and splits it into seperate fields in the database.
1 field will have the words, and the other will have the puncuation, special charaters, the's, and's, and other stuff. But it contains those weird box characters to tell it where to put the stuff. Then it uses another stored procedure to put it back in place. They are just not telling me how to do it. I just have to guess.
0
 
nplibAuthor Commented:
Also I found that the query browser I was using we causing the warnings, if I use the SQL Advantage that comes with Sybase it works without errors.

But now I have to figure out how to call the SP from ASP.
So unless you know I will just accept the answer you gave me, that gave me the result I was looking for in SQL Avantage.
0
 
grant300Commented:
Wow.  I don't know what to tell you about ASP but I suspect sending the funky stuff back and forth is going to cause you a problem someplace.  Give it a try and see what happens; maybe you'll get lucky.

Sorry I can't solve the Active Server Page issues for you.

Bill
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 6
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now