try this type of code, just copied it straight from one of our projects
<CFQUERY NAME="Insert" DATASOURCE="#Application.datasource#">
SET NOCOUNT ON
INSERT
INTO dbo.T_User
VALUES (
'#CompanySiteID#',
'#form.last_name#',
'#form.first_name#',
'#form.misc_num#',
'#form.misc_num#',
'#form.misc_num#',
null,
'#form.phone#',
'#form.fax#',
'#form.email#',
'#form.misc_num#',
'1')
select @@identity as new_id
SET NOCOUNT OFF
</cfquery>
<CFQUERY NAME="Insert2" DATASOURCE="#Application.datasource#">
INSERT
INTO dbo.T_User_Ship_To
VALUES (
'#insert.new_id#',
'#CompanySiteID#',
'#form.first_name#',
'#form.last_name#',
'#form.address1#',
'#form.address2#',
'#form.city#',
'#form.state_id#',
'#form.zip#',
'#form.country_id#',
'1',
'1')
</cfquery>
@@identity is the new id that the server created,works with SQL server
-----Original Message-----
From: Pooh Bear [mailto:[EMAIL PROTECTED]]
Sent: Friday, July 20, 2001 12:34 PM
To: CF-Talk
Subject: Inserting Records
ok guys, please tell me if there is a better way of doing this.
basically i have 2 tables, the second one having a many to many
relationship. What I am trying to do is insert a record into the first
table, then use the id (it's an identity field) of that row to insert into
the second table with some other information.
The way I am doing it now is having coldfusion insert the row, then do
another query to find the id of that row using a criteria such as email
(which is unique anyways). After i find the id, I do another insert into
the second row and enter in that id along with other information.
My goal is to skip that second part, where i have to do another query just
to get the id. is there a way to get the id automatically after it's been
created or something like that? I might go the route of having the DB
return the max id created, but I am paranoid that before it even starts to
get the id, another record has already been inserted, and we lose
consistency or somethin. dunno, i know u guys do this every day so how do u
do it?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Structure your ColdFusion code with Fusebox. Get the official book at
http://www.fusionauthority.com/bkinfo.cfm
Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists