House of Fusion
Search over 2,500 ColdFusion resources here
  
Home of the ColdFusion Community

Mailing Lists
Home /  Groups /  ColdFusion Talk (CF-Talk)

Datebase Question!

  << Previous Post |  RSS |  Sort Oldest First |  Sort Latest First |  Subscribe to this Group Next >> 
Database question.
cf coder
06/04/04 11:36 A
> From: cf coder
Philip Arnold
06/04/04 11:56 A
What database is it? SQL/Access/MySQL?
John Beynon
06/04/04 11:43 A
SQ
cf coder
06/04/04 11:48 A
Top  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
cf coder
06/04/2004 11:36 AM

Database question. I have a insert statment. I'm inserting a new record in the table. The table has a primary key (empID) Here is the code <cftransaction action="BEGIN"> <cfquery name="addNewEmp" datasource="db"> INSERT INTO ASSETS (   empName,   empDesk,   empAsset ) VALUES (   'blog',   '1,   'ast10' ) </cfquery> </cftransaction> I want to retreive the primary key (empID) value immediately after this statement. I tried this: <cfoutput>#addNewEmp.empID#</cfoutput> but get an error msg "Element empID is undefined in addNewEmp Can somebody please help Best Regards, cfcoder         __________________________________ Do you Yahoo!? Friends.  Fun.  Try the all-new Yahoo! Messenger. http://messenger.yahoo.com/

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Philip Arnold
06/04/2004 11:56 AM

----- Excess quoted text cut - see Original Post for more ----- You need to look into scope_identity() (if you're using SQL Server 2000) or @@identity (for SQL Server 7) Set nocount on Insert into table (fields) Values (values) Select scope_identity() as myID Set nocount on This will "return" the newly added identity field The problem with @@identity is that it returns the "last" identity inserted, so if you have triggers on your table which add to another table, then you will end up with the wrong identity field

Top  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
John Beynon
06/04/2004 11:43 AM

What database is it? SQL/Access/MySQL? Database question. I have a insert statment. I'm inserting a new record in the table. The table has a primary key (empID) Here is the code <cftransaction action="BEGIN"> <cfquery name="addNewEmp" datasource="db"> INSERT INTO ASSETS (   empName,   empDesk,   empAsset ) VALUES (   'blog',   '1,   'ast10' ) </cfquery> </cftransaction> I want to retreive the primary key (empID) value immediately after this statement. I tried this: <cfoutput>#addNewEmp.empID#</cfoutput> but get an error msg "Element empID is undefined in addNewEmp Can somebody please help Best Regards, cfcoder         __________________________________ Do you Yahoo!? Friends.  Fun.  Try the all-new Yahoo! Messenger. http://messenger.yahoo.com/

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Mark Drew
06/04/2004 11:53 AM

In Microsoft SQL server you can do something like: INSERT INTO table (col1, col2) VALUES 'val1', 'val2') SELECT thisUserID = @@IDENTITY SET NOCOUNT OFF; I hope that helps > > SQL

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
cf coder
06/04/2004 12:47 PM

Thanks so much Mark and Philip for your help. It works best regards, cfcoder


<< Previous Thread Today's Threads Next Thread >>

Search cf-talk

May 24, 2012

<<   <   Today   >   >>
Su Mo Tu We Th Fr Sa
     1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31     

Designer, Developer and mobile workflow conference