Solved

Stored Procedure with 2 input and 1 output variable

Posted on 2006-07-07
11
2,584 Views
Last Modified: 2008-01-09
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
Comment
Question by:nplib
  • 6
  • 3
  • 2
11 Comments
 
LVL 10

Expert Comment

by:bret
ID: 17059827
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
 
LVL 17

Author Comment

by:nplib
ID: 17060014
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
 
LVL 10

Expert Comment

by:bret
ID: 17060119
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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 17

Author Comment

by:nplib
ID: 17060219
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
 
LVL 19

Accepted Solution

by:
grant300 earned 250 total points
ID: 17063303
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
 
LVL 17

Author Comment

by:nplib
ID: 17065231
still get same warning messages
0
 
LVL 17

Author Comment

by:nplib
ID: 17065749
I don't know if I do or not, but asume that I do, I'll try anything now.
0
 
LVL 19

Expert Comment

by:grant300
ID: 17066946
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
 
LVL 17

Author Comment

by:nplib
ID: 17072879
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
 
LVL 17

Author Comment

by:nplib
ID: 17072895
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
 
LVL 19

Expert Comment

by:grant300
ID: 17077223
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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article explains the steps required to use the default Photos screensaver to display branding/corporate images
A project that enables an administrator to perform actions within a user session context not just at the time of login but any time later on day(s) or week(s) later.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa‚Ķ

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question