Hello,
Does anyone know how to find out the primary key value of last inserted
record? In SQL Server this would be done as follows:
INSERT INTO Customers(name, customerSince, isDeleted) VALUES (?, ?, ?);
SELECT id_customer, name, customerSince, isDeleted FROM Customers WHERE
(id_customer = @@IDENTITY)
TIA for any hints!
Filip Kierzek
Filip.Kierzek@m o b i l e w o r k s.pl
Art S. Kagel - 31 Jul 2003 13:28 GMT
I presume that id_customer is a SERIAL or SERIAL8 column. There are
two ways to get the value of the last inserted SERIAL and one way if the
column is SERIAL8. If you are using 4GL or ESQL/C you can look in the
sqlca data structure immediately following the insert to get the value if
it is SERIAL type, the field sqlca.sqlerrd[1] is the last inserted serial
value in ESQL/C (sqlca.sqlerrd[2] in 4GL). Otherwise you can get it
anytime in the same session before another insert to a table with a
SERIAL or SERIAL8 column with:
SELECT DBINFO( 'sqlca.sqlerrd1' )
FROM systables
WHERE tabid = 1;
-or for SERIAL8 -
SELECT DBINFO( 'serial8' )
FROM systables
WHERE tabid = 1;
You can also do as you have below for either DBINFO option:
SELECT id_customer, name, customerSince, isDeleted
FROM Customers
WHERE id_customer = DBINFO( 'sqlca.sqlerrd1' );
Art S. Kagel
> Hello,
>
[quoted text clipped - 9 lines]
> Filip Kierzek
> Filip.Kierzek@m o b i l e w o r k s.pl
Kristofer Andersson - 31 Jul 2003 18:33 GMT
This does not answer your question, but the following document is
useful for anyone who is used to SQL Server and new to Informix:
http://www-3.ibm.com/software/data/informix/pubs/smv/pdfs/microsoft-sql.pdf
It tells you what the equivalent Informix syntax is for common SQL
Server commands, functions etc and provide stored procedures for those
that don't have an equivalent. @@Identity is not covered though...