What is the best syntax to use within a trigger for this problem?
Table: MYCURRENTTABLE (one record per MYID)
Fields: MYCT_KEY, MYID, MYCODE, .....
Table: MYHISTORICALTABLE (multiple records per MYID)
Fields: MYHT_KEY, MYID, MYCODE, .....
When a record gets inserted into the MYHISTORICALTABLE, the MYCODE field needs to be populated with the value currently sitting in the MYCODE field of the MYCURRENTTABLE. I've already got a trigger on the MYHISTORICALTABLE which is performing other tasks. I just need to add logic to the trigger to handle this new need.
The code needs to work both a single record insert and a multiple record insert. MYID will always already exist within the MYCURRENTTABLE. MYHT_KEY is an identity column. MYCODE may or may not be included in the insert statement. If MYCODE IS included, it should keep that value. If MYCODE is NULL or is NOT included in the insert statement, the value should be retrieved from the MYCURRENTTABLE.
Thanks
Table: MYCURRENTTABLE (one record per MYID)
Fields: MYCT_KEY, MYID, MYCODE, .....
Table: MYHISTORICALTABLE (multiple records per MYID)
Fields: MYHT_KEY, MYID, MYCODE, .....
When a record gets inserted into the MYHISTORICALTABLE, the MYCODE field needs to be populated with the value currently sitting in the MYCODE field of the MYCURRENTTABLE. I've already got a trigger on the MYHISTORICALTABLE which is performing other tasks. I just need to add logic to the trigger to handle this new need.
The code needs to work both a single record insert and a multiple record insert. MYID will always already exist within the MYCURRENTTABLE. MYHT_KEY is an identity column. MYCODE may or may not be included in the insert statement. If MYCODE IS included, it should keep that value. If MYCODE is NULL or is NOT included in the insert statement, the value should be retrieved from the MYCURRENTTABLE.
Thanks