punkish has asked for the wisdom of the Perl Monks concerning the following question:
I created a stored proc in SQL Server like so
CREATE PROCEDURE sp_myproc @a VARCHAR(250), @b VARCHAR(250) AS BEGIN TRAN ..bunch of code.. DECLARE @id NUMERIC, @newid NUMERIC SELECT @id = id, @newid = (id + 1) FROM sometable WHERE (some condition) ..more bunch of code.. -- Now, insert a new record in request INSERT INTO anothertable (id, othercols) VALUES (@id, othervals) -- Update the request id UPDATE yetanothertable SET id = @newid WHERE (someothercondition) COMMIT TRAN RETURN @id
Which I call via DBD::OBDC like so
my $sth = $dbh->prepare("EXEC sp_myproc ?, ?"); my $id = $sth->execute('foo', 'bar');
Obviously my code above is wrong because the $id captured by the Perl code is not the same as the @id created in the stored proc. My $id is always 1, which is, I am guessing, indicating success at running the stored proc. I want to get back that @id that I created in the stored proc.
In general, how do I get one or more values back from a complicated (or not so) stored procedure back in my Perl code so I can work with it?
Many thanks in advance.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Capturing a value returned from a stored procedure
by runrig (Abbot) on Dec 21, 2004 at 00:03 UTC | |
by punkish (Priest) on Dec 21, 2004 at 00:11 UTC | |
|
Re: Capturing a value returned from a stored procedure
by jZed (Prior) on Dec 20, 2004 at 23:53 UTC | |
by punkish (Priest) on Dec 21, 2004 at 00:01 UTC |