phweston
Programmer
- May 8, 2003
- 38
I am putting together a trigger to update 2 fields in a second table when a field is changed in the first table.
The Trigger should work like this. The user updates a customer name in Table 1, and the customer name is updated to reflect the changes in Table2. In addition, the trigger should update the field "edit_date" in table2 with the current system date.
CREATE TRIGGER Customer_Name_Update
ON Table1
for update
as
If update (Customer_Name)
UPDATE Table2
SET Table2.CUSTOMER_NAME = Table1.customer_name
FROM Table2
INNER JOIN Table1
ON Table2.customer_code = Table1.customer_code
if update(Customer_Name)
UPDATE TABLE2
SET TABLE2.edit_Date = getdate()
FROM TABLE2INNER JOIN TABLE1
ON TABLE2.customer_code = TABLE1.customer_code
The first part where the customer name is updated in table when it is changed in Table 1 works fine.
What is not working is the part where a date field is updated. This part updates the entire Table 2 for the Edit Date Field.
Any suggestions?
The Trigger should work like this. The user updates a customer name in Table 1, and the customer name is updated to reflect the changes in Table2. In addition, the trigger should update the field "edit_date" in table2 with the current system date.
CREATE TRIGGER Customer_Name_Update
ON Table1
for update
as
If update (Customer_Name)
UPDATE Table2
SET Table2.CUSTOMER_NAME = Table1.customer_name
FROM Table2
INNER JOIN Table1
ON Table2.customer_code = Table1.customer_code
if update(Customer_Name)
UPDATE TABLE2
SET TABLE2.edit_Date = getdate()
FROM TABLE2INNER JOIN TABLE1
ON TABLE2.customer_code = TABLE1.customer_code
The first part where the customer name is updated in table when it is changed in Table 1 works fine.
What is not working is the part where a date field is updated. This part updates the entire Table 2 for the Edit Date Field.
Any suggestions?