• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Retrieve @@IDENTITY on CFQUERY

Guest
Aug 08, 2006 Aug 08, 2006

Copy link to clipboard

Copied

New to CF ... How can I retrieve @@IDENTITY when using a CFQUERY? I could do it in ASP but iccck, who wants to talk about that anymore.
TOPICS
Database access

Views

1.6K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Deleted User
Aug 08, 2006 Aug 08, 2006

Votes

Translate

Translate
LEGEND ,
Aug 08, 2006 Aug 08, 2006

Copy link to clipboard

Copied

Yes you can, but I dont' so I can't tell you how. I have seen it
discussed many times so I know it is possible.

mikeap wrote:
> New to CF ... How can I retrieve @@IDENTITY when using a CFQUERY? I could do it in ASP but iccck, who wants to talk about that anymore.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Aug 08, 2006 Aug 08, 2006

Copy link to clipboard

Copied

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 08, 2006 Aug 08, 2006

Copy link to clipboard

Copied

this would depend on the database being used...(works in MS SQL, MS
Access, MySQL to name a few)
If you can run more than 1 sql statement in a cfquery tag then you can
run it immediately after the insert (using a ;). If not, wrap 2 cfquery
tags in a transaction and run the @@IDENTITY query second.

SELECT @@IDENTITY AS thelatest

then retrieve it through yourqueryname.thelatest .

If on SQL Server...you might want to look at scope_identity()
HTH
--
Tim Carley
www.recfusion.com
info@NOSPAMINGrecfusion.com

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 01, 2009 Aug 01, 2009

Copy link to clipboard

Copied

Better yet, create the query as a stored procedure and put "SELECT @@IDENTITY AS thelatest" immediately after the insert; this way you won't have to put it inside a transaction in order to know that you've got the latest identity.

^_^

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Aug 07, 2009 Aug 07, 2009

Copy link to clipboard

Copied

LATEST

Take a look at the CFQUERY documentation.  You can use IDENTITYCOL property of a result to get a new identity value.  Note that IDENTITYCOL is MS SQL Server specific, see the documentation for the properties used for other databases.

CFQUERY

http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=Tags_p-q_17.html#1102316

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation