In Transact-SQL (SQL Server), you can use @@identity.

>From Help:

@@IDENTITY
-------------------------------------------------
Returns the last-inserted identity value. 
Syntax

@@IDENTITY

Return Types

numeric

Remarks

After an INSERT, SELECT INTO, or bulk copy statement completes, @@IDENTITY
contains the last identity value generated by the statement. If the
statement did not affect any tables with identity columns, @@IDENTITY
returns NULL. If multiple rows are inserted, generating multiple identity
values, @@IDENTITY returns the last identity value generated. If the
statement fires one or more triggers that perform inserts that generate
identity values, calling @@IDENTITY immediately after the statement returns
the last identity value generated by the triggers. The @@IDENTITY value does
not revert to a previous setting if the INSERT or SELECT INTO statement or
bulk copy fails, or if the transaction is rolled back.

---------------------------------------------------

-----Original Message-----
From: Chris Lott [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, October 04, 2000 3:02 PM
To: CF-Talk
Subject: Last Transaction ID


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Is there any built-in function that will give me the ID of the most recent
database insert? For instance, when the user inserts a new record, I want
to immediately retrieve the new record ID for use in a confirmation message
and email.

I suppose I can wrap the insert and then a select MAX(id) for that
particular user in a CFTRANSACTION, but there must be a more elegant way?

c
- --
Chris Lott <[EMAIL PROTECTED]>| IT Manager|p907-474-3494

-----BEGIN PGP SIGNATURE-----
Version: 6.5.8ckt http://irfaiad.virtualave.net/

iQA/AwUBOduMztaLYehRBGz9EQJIUACfWr2TysaV5wHTvAV4nvjn1Zdo0nAAoPck
BcMa40G39FpQLcoSJ4nCIiwS
=YFaI
-----END PGP SIGNATURE-----


----------------------------------------------------------------------------
--
Archives: http://www.mail-archive.com/[email protected]/
To Unsubscribe visit
http://www.houseoffusion.com/index.cfm?sidebar=lists&body=lists/cf_talk or
send a message to [EMAIL PROTECTED] with 'unsubscribe' in
the body.
------------------------------------------------------------------------------
Archives: http://www.mail-archive.com/[email protected]/
To Unsubscribe visit 
http://www.houseoffusion.com/index.cfm?sidebar=lists&body=lists/cf_talk or send a 
message to [EMAIL PROTECTED] with 'unsubscribe' in the body.

Reply via email to