On Sun, 2004-02-01 at 07:09, Stuart Kidd wrote:
> Hi guys,
>  
> I'm inserting a record to a database, but once I have inserted the
> record I want to email the user their details including their UserID
> which is an autonumber (primary).
>  
> To grab the last inserted row should I use the CFLOCK around my query
> and my cfmail?  Is there such a thing as Last.UserID which will give me
> the last insert of UserID?
>  
Well if you are using MSSQL you can use the variable @@identity to get
the primary key of the last inserted record for example:

<cfquery name="blarg" datasouce="yadda">
SET NOCOUNT ON
INSERT INTO booga (
fname,
lname
) VALUES (
'bob',
'superfly'
)

SELECT @@identity as newid

SET NOCOUNT OFF
</cfquery>

<cfoutput>#blarg.newid#</cfoutput>

most databases should have a similar function (prolly not access tho)

Cheers

--
Vale,
Rob

Luxuria immodica insaniam creat.
Sanam formam viatae conservate!

http://www.rohanclan.com
http://treebeard.sourceforge.net
http://ashpool.sourceforge.net
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]

Reply via email to