Hello,

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.


In reply to Capturing a value returned from a stored procedure by punkish

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.