Solved

Coldfusion Last Inserted value in database

Posted on 2014-11-04
3
267 Views
Last Modified: 2014-11-05
Is there any function in coldfusion, i want last inserted value from database.
if there is no function so what is the right way to do it.

database could be oracle or MSSQL

Thank you.....
0
Comment
Question by:xeondxb
3 Comments
 
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
Comment Utility
I don't believe Coldfusion is much more than an interface to a database.  It only remembers/tracks what you tell it to.

Unless you return the value from the database, I don;t think it has any 'smarts' built in.

An example:
Oracle has a 'returning' clause hat allows you to return specific values from DML.  If the app coded the DML to take advantage of the returning clause and handled the return values properly, then yes.

If not, I'm afraid you might be out of luck.

Then again, I'm not a Coldfusion expert...
0
 
LVL 52

Accepted Solution

by:
_agx_ earned 500 total points
Comment Utility
EDIT:

I don't use Oracle, but for SQL Server table's that have an IDENTITY column, you can use cfquery's "result" attribute to return the new record ID from an INSERT.

       <cfquery name="addRecord" result="yourResult" ...>
              INSERT INTO SomeTable (..Columns..) VALUES ( ... values ...)
       </cfquery>

        The new identity value is <cfoutput>#yourResult.IDENTITYCOL#</cfoutput>

The exact syntax is db dependent. For Oracle, try the ROWID value. For more details see the cfquery docs.
0
 

Author Closing Comment

by:xeondxb
Comment Utility
Thanks
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now