0

I am new to Gupta Sql Base. I would like to know how to get the last inserted record in Gupta SQL

Kiran B
  • 683
  • 10
  • 21
  • I know this has already been answered , but if you need to know more about SQLBase, here is a link to some manuals for every version from v8 thru v12.1 : http://samples.tdcommunity.net/index.php?dir=SqlBase/SqlBase_Books/ – Steve Leighton Jul 20 '18 at 01:53

1 Answers1

0

If you are using SYSDBSequence.NextVal to generate your Primary Key, either within the Insert stmt, or prior to the Insert , then you can retrieve it back immediately after the Insert by Selecting Where [Primary Key] = SYSDBSequence.Currval e.g. Select Name from Patient Where Patient_Id = SYSDBSequence.Currval

Alternatively, If your Primary Key column has been defined as AUTO_INCREMENT , you can select it back after the Insert using MAX( [Primary Key ] ) e.g. Select Name from Patient Where Patient_Id = (Select MAX( Patient_Id) from Patient )

Alternatively, if none of the above, then write an Insert Trigger to either return it , or to store the PK in a table so you will always have the latest PK recorded for you.

You may like to join the Gupta users forum at enter link description here or there is much archived information at enter link description here

Steve Leighton
  • 790
  • 5
  • 15
  • Is there any equivalent for MS SQL @@identity in Sql base? I am looking for a generic way. The MAX value will not be correct if we do multiple inserts at the same time right? – Kiran B Jun 02 '17 at 06:36
  • Then use SYSDBSequence.NextVal to do the insert - and then SYSDBSequence.Currval will contain the value just inserted - exactly like @@Identity. Better still - you didn't need to define the column as an Identity column in the first place. – Steve Leighton Jun 04 '17 at 03:17