set variable equal to value from a database recordset
This is for Coldfusion version 8.
I have two tables which I am inserting data into. After I insert a record into the first table, I need to use the id (auto incremented, not something I already have) of the new record as part of the data i input into the second table.
I'm having trouble nailing down the syntax to get me there. I've searched the documentation, any thoughts on what topic I should have been looking under would be welcome as well.
Any help would be appreciated, thanks.
-----------------------------------
<!--- This table has an id column which autoincrements --->
<cfquery datasource="labdsn" name="newLabDataRecord">INSERT INTO LabData (savedLab, lastSavedBy ) VALUES ('Data data data','555' )</cfquery>
<!--- find the value of that new id --->
<cfquery datasource="labdsn" name="maxLabIDRecord">Select max(id) FROM LabData</cfquery>
<!--- This generates the error. Not surprised, but not sure what it should be --->
<cfset maxID= <cfoutput query = "rsMaxLabIDRecord">#rsMaxLabIDRecord.id#</cfoutput> >
<cfquery datasource="labdsn" name="newUserRecord">INSERT INTO UsersVsLab (userID, whichLab,LabID ) VALUES ('2',1 , <cfqueryparam value="#maxID#"> )</cfquery>
<!--- This was another syntax I tried --->
<!--- cfquery datasource="labdsn" name="newUserRecord">INSERT INTO UsersVsLab (userID, whichLab,LabID )
VALUES
('2',1 , <cfqueryparam value=<cfoutput query = "rsMaxLabIDRecord">#rsMaxLabIDRecord.id#</cfoutput> > )</cfquery --->
