How insert into 2 tables.
Hi ,
I have 2 tables like this:
Table 1:
CustomerID (auto number)
other feilds,
Table2:
EventID(auto number)
CustomerID
other feilds,
I would like to insert a record into these two tables. I am using CFC to insert, I have problem to insert CustomerID into the second table. I really appreciate if you can help me.
<cfcomponent>
<cffunction name="Add" access="public" returntype="void">
<cfargument name="formData" type="struct" required="yes">
<cfquery datasource="DB">
INSERT INTO dbo.Table 1
(
other feilds
)
VALUES
('#formData.feildsName#'
)
</cfquery>
<cfquery name="qGetID" datasource="DB">
SELECT MAX(CustomerID ) AS ID
FROM table1
</cfquery>
<cfquery datasource="DB">
INSERT INTO dbo.table2
(
ID ,
other feilds
)
VALUES
( '#ID#',
('#formData.feildsName#'
)
Thanks.
