I do it this way

<cftransaction>
 <cfquery name="insertRecord" datasource="foo">
  SET nocount on;
  INSERT INTO table
  (col1, col2, col3)
  VALUES
  ('blah', 'blah', 'blah');
  SELECT @@Identity as NewID;
  SET nocount off;
 </cfquery>
</cftransaction>

This gives #insertRecord.newID# the ID you just inserted.

______________________
steve oliver
cresco technologies, inc.
http://www.crescotech.com


-----Original Message-----
From: Voris, Jim [mailto:[EMAIL PROTECTED]] 
Sent: Tuesday, January 29, 2002 3:12 PM
To: CF-Talk
Subject: Getting the id of the row you just inserted...


It seems to me that there are three basic ways to get the id of the row
you
just inserted.
1)  @@identity
and
2)  cflocking the insert statement and the select max(id) statement.
and
3)  qualifying the select max(id) statement to avoid problems caused by
multiple threads.

I'm curious which method people use and which they find to be the best.


______________________________________________________________________
Get Your Own Dedicated Windows 2000 Server
  PIII 800 / 256 MB RAM / 40 GB HD / 20 GB MO/XFER
  Instant Activation � $99/Month � Free Setup
  http://www.pennyhost.com/redirect.cfm?adcode=coldfusionb
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

Reply via email to