Thanks to everyone who responded. A half a fresh night's sleep, 200 cathartic pages more of
Harry Potter, and of course the replies I received here got me hitting things from different angles, and I've gotten it to work. I'm posting what I did here because hopefully this will help the next person who searches for stored procedures and find lots of mostly helpful tidbits =)
This is in reference (as the title suggests) to calling stored procedures via
DBI&
DBD::ODBC on Win32 systems to an m$ SQL server. The test table contained two fields: InField is a varchar field, and OutField is an int, autonumbering.
CREATE PROCEDURE TestProc
@InField varchar(50)
AS
INSERT INTO TestTable
(InField)
VALUES
(@InField)
SELECT @@identity
GO
For those as unfamiliar with stored procs as I am, @@identity on MS SQL returns the last selected identity-type field (ie: autonumbering) in the previous action. Here is the perl code which drops off data and picks up the auto-number field.
..connect to db..
my $sth = $dbh->prepare('{call TestProc(?)}');
my $a = "TEST";
$sth->bind_param(1, $a) or die $sth->errstr;
$sth->execute();
my $results = $sth->fetch();
$sth->finish();
$dbh->disconnect;
print "results are $$results[0]\n";
Not the prettiest piece of code, but hopefully it's basic enough to be clear to somebody looking to accomplish the same thing.
Thanks again for the help and the fresh angles. The myriad docs and posts on various sites all had different ways to go about it, and whether or not they work seems quite dependant on so many things.
-=rev=-
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.