Suppose I have a stored procedure like this:

CREATE PROCEDURE dbo.Foo ( @Required Int, @Optional Int = 0 ) AS ...
I know I can call the procedure via
my $sth2 = $db->prepare('EXEC dbo.Foo ?, ?'); $sth2->execute(1,2);
or
my $sth1 = $db->prepare('EXEC dbo.Foo ?'); $sth1->execute(1); # use the default for the second param
But is there any way to specify I want to use the default value even with the first prepared statement? So that I don't have to prepare the same procedure twice...

I can't call $sth2->execute(1) since that triggers an error (execute failed: called with 1 bind variables when 2 are needed), I can't use undef since that would translate to NULL, ...

Thanks, Jenda
XML sucks. Badly. SOAP on the other hand is the most powerfull vacuum pump ever invented.


In reply to DBI->MS SQL, optional parameters to stored procedures by Jenda

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.