Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
Database Servers
DB2InformixIngresMS SQLOraclePervasive.SQLPostgreSQLProgressSybase
Desktop Databases
FileMakerFoxProMS AccessParadox
General
General DB TopicsDatabase Theory
Related Topics
Java Development.NET DevelopmentVB DevelopmentMore Topics ...

Database Forum / Informix Topics / July 2003

Tip: Looking for answers? Try searching our database.

@@IDENTITY in Informix

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Filip Kierzek - 31 Jul 2003 12:30 GMT
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...
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.