Michael Riley - AKA Gunny Michael Riley - AKA Gunny - 1 year ago 103
SQL Question

How to Return the ID Value When Inserting a Record Using ElevateDB

With SQL server you can simply return

to get the
value of the last insert.

Is there a way to do this using ?

Answer Source

ElevateDB provides a LASTIDENTITY function which returns the last identity value assigned to the specified column in the specified table.

SELECT LASTIDENTITY('Customer', 'CustNo') AS LastCustNo

You can also obtain the same information using the INSERT statement.

EDBQuery1.SQL.Add('INSERT INTO Table1 (ID, Text1)');
EDBQuery1.SQL.Add('VALUES(:ID, :Text1)');
EDBQuery1.ParamByName('Text1').AsString:='Some text';

INSERT statements automatically set all parameters to IN/OUT so that any generated/computed column values (including IDENTITY columns) can be retrieved via the same parameters after the INSERT is executed.

The above example is from the Support Forum.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download