If you are using sql server try this...
<CFQUERY datasource="foo" name=bar">
SET NOCOUNT ON
INSERT INTO [yourtable](field1, field2)
VALUES ('text', 'text')
SELECT @@Identity AS newID
SET NOCOUNT OFF
</CFQUERY>
Should return the ID as
<CFOUTPUT query="bar">
#newID# <!--- should equal the new ID --->
</CFOUTPUT>
/* This works on SQL Server 2000 */
HTH,
Jeff Garza
Lead Developer/Webmaster
Spectrum Astro, Inc.
480.892.8200
[EMAIL PROTECTED]
http://www.spectrumastro.com
-----Original Message-----
From: Tyler Silcox [mailto:[EMAIL PROTECTED]]
Sent: Thursday, December 20, 2001 1:31 PM
To: CF-Talk
Subject: Returning IDs off a query...
I've been saving this question for a rainy day, and while it's not rainy, it
could be getting a little stormy...what is the best way to return a freshly
submitted ID from a cfquery? Should I use a getMax SQL function with
cftransaction tag pair around the insert and select queries or should I
retrieve the @@identity in a separate cfquery statement? Any takers?
Tyler
______________________________________________________________________
Why Share?
Dedicated Win 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=coldfusionc
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