If you are using SQL server and are within a transaction you can use SELECT @@identity AS newid FROM table
It holds the value of the last id inserted in the table for that transaction Kevin -----Original Message----- From: Donnie Bachan [mailto:[EMAIL PROTECTED]] Sent: Thursday, May 16, 2002 1:59 PM To: CF-Talk Subject: RE: Inserting into 2 tables with a relationship Okay let's say that you are incrementing the primary key in the first table upon an insert, and then you want to insert the value of that key into the second table as var_id, what you have to do is after you did the first insert, you need to select max(variable) as new_var_id from table1 This is done to get the value of the primary key that was created on the insert, there is no other way to get that value. Then you insert new_var_id as var_id into table2 I hope this is what you are looking for. I assume the reason it is inserting 0 is because you have the field set to default to zero when the value is not passed. HTH Donnie Bachan Phone: (718) 217-2883 ICQ#: 28006783 "Nitendo Vinces - By Striving You Shall Conquer" ====================================================================== The information transmitted is intended only for the person or entity to which it is addressed and may contain confidential and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from any computer. ______________________________________________________________________ This list and all House of Fusion resources hosted by CFHosting.com. The place for dependable ColdFusion Hosting. FAQ: http://www.thenetprofits.co.uk/coldfusion/faq Archives: http://www.mail-archive.com/cf-talk@houseoffusion.com/ Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists