Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 4 of 4 total
Thread Output parameter in Query, not script
Sun, Feb 7 2010 11:45 PMPermanent Link

Peter
Hello

I would like to use an output parametr to obtain the seed value used in the current query's operation. By that I mean, the first field in the table is a
an IDENTITY field, generated by default, so that field is no longer in the INSERT statement. However, I would like to get the value of the IDENTITY
field as part of the process, as sometimes I need to use that value to create a detail table record.

The existing code looks like this...

   AQuery.SQL.Add('INSERT INTO "Drafts" (Client_ID, LastSaved,'+
   ' Description, LetterType) VALUES (:Client_ID, :LastSaved, :Description, :LetterType)');
  
   AQuery.ParamByName('Client_ID').AsInteger := iClientID;
   AQuery.ParamByName('LastSaved').AsDateTime := Now;
   AQuery.ParamByName('LetterType').AsInteger := iLetterType;
   AQuery.ParamByName('Description').AsString := sFileName;
   AQuery.Prepare;
   AQuery.ExecSQL;

...which works just fine, as do numerous similar inserts. What I would like to know is how to use the Output parameter to read the value that was
inserted into the first (generated) field, which is named DraftID.

How can I define that parameter then read it?

Regards & TIA

Peter
Mon, Feb 8 2010 2:48 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Peter


Sound like you're asking for last autoinc. In which case search in the elevatedb.sql newsgroup for the thread DBISAM -> EDB: LASTAUTOINC

Roy Lambert [Team Elevate]
Mon, Feb 8 2010 2:58 AMPermanent Link

Uli Becker
Peter,

> ..which works just fine, as do numerous similar inserts. What I would like to know is how to use the Output parameter to read the value that was
> inserted into the first (generated) field, which is named DraftID.
>
> How can I define that parameter then read it?

with AQuery do
  begin
    sql.add('insert into Drafts (DraftsID,CientID) values
(:ReturnIdentity,:FClientID)');
    ParamByName('FClientID').asInteger := iClientID;
    ParamByName('ReturnIdentity').ParamType := ptInputOutput;
    ExecSQL;
    WantedID := ParamByName('ReturnIdentity').asInteger;
  end;

Regards Uli
Mon, Feb 8 2010 4:52 AMPermanent Link

Peter
Uli & Roy

Thank you very much, I see how it works now.

Regards

Peter
Image