Getting the value of an IDENTITY column after an INSERT query

Getting the value of an IDENTITY column after an INSERT query

Post by Enrique Travies » Fri, 21 Mar 1997 04:00:00



Does anybody know of a way to obtain the the value of an IDENTITY column
using ODBC/RDO after an INSERT query has been performed.

I can issue another SELECT MAX(fieldname)  query but that method does not
hold up too well under multi-user access.

Any help would be appreciated.

Enrique Travieso

 
 
 

Getting the value of an IDENTITY column after an INSERT query

Post by George Khali » Sat, 22 Mar 1997 04:00:00


I do it using a stored procedure which has an output parameter which
passes back the IDENTITY column value.  Here is an example:

CREATE PROCEDURE spInsert

output parameter */

AS
BEGIN
        INSERT INTO table (dumb_value)



END

Then in  ODBC you should bind a parameter to accept the identity value
and use the following SQL statement and pass it to SQLExecDirect():

"{ CALL spInsert(?, dumb_value) }"

That should work.  Good luck.

George Khalifa

On Thu, 20 Mar 1997 12:04:53 -0800, "Enrique Travieso"


>Does anybody know of a way to obtain the the value of an IDENTITY column
>using ODBC/RDO after an INSERT query has been performed.

>I can issue another SELECT MAX(fieldname)  query but that method does not
>hold up too well under multi-user access.

>Any help would be appreciated.

>Enrique Travieso



 
 
 

Getting the value of an IDENTITY column after an INSERT query

Post by Rick Lemon » Sat, 22 Mar 1997 04:00:00


Richard Litofsky posted an excellent solution not long ago. Check the
subject "AUTOINCREMENT and ASP - How to obtain value after insert" dated
3/19/97. It works. I'm using it.

----

Jason Data Services, Inc. http://www.jdsinc.com
My mail reader can beat up your mail reader.



> Does anybody know of a way to obtain the the value of an IDENTITY column
> using ODBC/RDO after an INSERT query has been performed.

> I can issue another SELECT MAX(fieldname)  query but that method does not
> hold up too well under multi-user access.

> Any help would be appreciated.

> Enrique Travieso


 
 
 

1. Getting Back Identity column value on Insert using RDS

 Does anyone know of an easy way to get back the identity column value on an
insert using
RDS from a web page ?


to work with RDS. It always
returns NULL, may be because RDS drops the connection after each query ?

Sending the insert record to a DCOM object on the server and have that do
the insert and the return the identity value seems to be the only solution
to me. Is there anyway to avoid this extra step ?

Thanks in advance for any suggestions

Sundar B

2. Shut down event?

3. Getting the new identity value from an Insert query

4. how can I convert/open LDF file to TXT?

5. INSERT INTO with SELECT DISTINCT causes a zero value to be inserted into an IDENTITY column

6. shell(.f.)

7. Getting rid of the IDENTITY property on a column withou getting rid of the column

8. ENGLAND -- Oracle and Solaris/Unix experience needed. All levels. EU candidates welcome.

9. Getting IDENTITY value BEFORE an insert(?!)

10. Getting the value of an autoincrement or identity field during an sql insert

11. getting identity value after insert

12. Getting IDENTITY column value

13. Getting auto-incremented identity value on insert...