From: xtrack <[EMAIL PROTECTED]>
> I am trying (as perl newbie) to fetch the returned value of a SELECT
> @@IDENTITY; the database used is MSSSQL on Win2k Server. The problem
> is that after the INSERT query i cannot get the returned value
> correcly Any suggestion is welcome and appreciate.
>
> thanks in advance.
>
> ----[ perl code follow
>
> # perl started with #!/usr/bin/perl -w
> # use DBI;
> # use scrict;
> # use other misc...
> # dbh and other still created
> # [...]
>
> $query = $dbh->prepare("begin
> INSERT INTO MAIL (DATEI, DATEM, SUB, OBJ, INV)
> VALUES ('$today', '$date', $qsubject, $qbody, '$inv_ric');
> SELECT [EMAIL PROTECTED]@IDENTITY; end ") or
> die "Can't prepare the SQL statement: $DBI::errstr";
>
> $query->execute() or die "Can't execute the SQL statement:
> $DBI::errstr";
>
> my $row = $query->fetchrow_arrayref();
> my $inserted_id = $row->[0];
>
> print ("IDENTITY: $inserted_id\n");
Seems to work fine to me (DBI 1.32, DBD::ODBC 1.04, MS SQL Server
2000SP3).
Try to add
SET NOCOUNT ON
just before the INSERT. I know I've had some problems because of this
some time ago.
Jenda
===== [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =====
When it comes to wine, women and song, wizards are allowed
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery