[help] select @@IDENTITY after INSERT

From: Xtrack (xtrack_at_myrealbox.com)
Date: 05/23/04

  • Next message: Xtrack: "Re: RE: [help] select @@IDENTITY after INSERT"
    Date: Sun, 23 May 2004 14:08:19 +0200
    To: dbi-users@perl.org
    
    

    Hi to the list,

    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 \@\@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");

    my $list = $query->dump_results();
    print $list;

    ----[ sample output follow

    query = begin INSERT INTO MAIL (DATEI, DATEM, SUB, OBJ,
    INV) VALUES ('4/23/104 13:58:43', '05/11/2004 11:56:51',
    'test1
    ', 'ARRAY(0x84eb058)', '1'); SELECT @@IDENTITY; end
    IDENTITY:

    0 rows
    0

    -----[ sample SQL client transcript

    SQL> INSERT INTO MAIL (DATEI, DATEM, SUB, OBJ, INV)
    VALUES ('4/23/104 13:58:43', '05/11/2004 11:56:51', 'test1',
    'ARRAY(0x84eb058)', '1'); SELECT @@IDENTITY;
    query = INSERT INTO MAIL (DATEI, DATEM, SUB, OBJ,
    INV) VALUES ('4/23/104 13:58:43', '05/11/2004 11:56:51',
    'test1', 'ARRAY(0x84eb058)', '1'); SELECT @@IDENTITY;
    +-----------+
    | |
    +-----------+
    | 327 |
    +-----------+
    1 rows affected
    SQL>

    PS which is the appropriate function to fetch data from $qbody and
    insert into query the data insted of ARRAY(0x....) ?


  • Next message: Xtrack: "Re: RE: [help] select @@IDENTITY after INSERT"

    Relevant Pages

    • Re: Einzelschritt vs. Komplettdurchlauf
      ... Wenn die Datei offen ist, ... Sub Ist_Datei_offen ... Private WithEvents cmdClose As CommandButton ... Private mFileNumber As Integer ...
      (microsoft.public.de.vb)
    • Re: Einzelschritt vs. Komplettdurchlauf
      ... Datei arbeiten wollte. ... Sub Ist_Datei_offen ... Private WithEvents cmdClose As CommandButton ... Private mFileNumber As Integer ...
      (microsoft.public.de.vb)
    • =?Utf-8?Q?Re:_*.dat_Datei_=C3=B6ffnen?=
      ... eine Combobox, dessen inhalt in eine Datei ... > Private Sub FRM_Main_Load(ByVal sender As Object, ... > End Sub ...
      (microsoft.public.de.german.entwickler.dotnet.vb)
    • Re: Daten schreiben in txt-File
      ... Die Get-Anweisung beim Zugriff auf eine solche Datei liest die Daten ja ... Die beiden Integerwerte werden ganz einfach als jeweils 2 Byte pro Integer ... Private Sub WriteFile() ... Dim FN As Integer ...
      (microsoft.public.de.vb)
    • Re: *.dat Datei öffnen
      ... eine Combobox, dessen inhalt in eine Datei ... Private Sub FRM_Main_Load(ByVal sender As Object, ... End Sub ...
      (microsoft.public.de.german.entwickler.dotnet.vb)