Answered
Passing a value from one table to another
Access Database:
I have 2 tables, table 1 has a field that is a primary key (indexed, no dups), table 2 has a field that needs to receive the same number as represented in table 1 .
The problem is that when the query runs it gets the MAX (number) but when it's inserted into table 2, all of the records in table 2 are updated with this number.
Is there a way to prevent all of the records in table 2 form being updated and only the newest record receiving the number from table 1?
Any Ideas?
This is my query:
<cftransaction>
<cfif len(trim(form.Time_Spent)) gt 0>
<cfquery name="InsertRecord" datasource="NBProdReports">
Insert Into TblMasterTrans (Time_Spent) Values ('#form.Time_Spent#')
</cfquery>
</cfif>
<cfif len(trim(form.Notes)) gt 0>
<cfquery name="InsertRecord" datasource="NBProdReports">
Insert Into TblContractInfo_SubMenuTable (Contract_Number , Transaction_Type , Num_Checks_Trans , Notes)
Values ('#form.Contract_Number#','#form.Trans_Type#','#form.Num_Checks_Trans#','#form.Notes#')
</cfquery>
</cfif>
<cfquery name="getTask_Number" datasource="NBProdReports">
SELECT MAX (Task_Number) AS theTask_Number
From TblMasterTrans
</cfquery>
<cfquery name="SetTaskNumber" datasource="NBProdReports">
Update TblContractInfo_SubMenuTable
Set
Task_Number=#getTask_Number.theTask_Number#
Where Task_Number = Null
</cfquery>
</cftransaction>
I have 2 tables, table 1 has a field that is a primary key (indexed, no dups), table 2 has a field that needs to receive the same number as represented in table 1 .
The problem is that when the query runs it gets the MAX (number) but when it's inserted into table 2, all of the records in table 2 are updated with this number.
Is there a way to prevent all of the records in table 2 form being updated and only the newest record receiving the number from table 1?
Any Ideas?
This is my query:
<cftransaction>
<cfif len(trim(form.Time_Spent)) gt 0>
<cfquery name="InsertRecord" datasource="NBProdReports">
Insert Into TblMasterTrans (Time_Spent) Values ('#form.Time_Spent#')
</cfquery>
</cfif>
<cfif len(trim(form.Notes)) gt 0>
<cfquery name="InsertRecord" datasource="NBProdReports">
Insert Into TblContractInfo_SubMenuTable (Contract_Number , Transaction_Type , Num_Checks_Trans , Notes)
Values ('#form.Contract_Number#','#form.Trans_Type#','#form.Num_Checks_Trans#','#form.Notes#')
</cfquery>
</cfif>
<cfquery name="getTask_Number" datasource="NBProdReports">
SELECT MAX (Task_Number) AS theTask_Number
From TblMasterTrans
</cfquery>
<cfquery name="SetTaskNumber" datasource="NBProdReports">
Update TblContractInfo_SubMenuTable
Set
Task_Number=#getTask_Number.theTask_Number#
Where Task_Number = Null
</cfquery>
</cftransaction>