Link to home
Start Free TrialLog in
Avatar of CLoucas
CLoucas

asked on

Conditionally updating a table value in a table trigger

I have defined a trigger on a table which fires everytime a row is inserted.  When a row is inserted, I update a second table's 'status' column with the new row's status field as follows:

CREATE TRIGGER Status_insert_trigger
ON Status
AFTER INSERT
AS
UPDATE Customers
SET Status = i.status
FROM Customers
INNER JOIN Inserted i ON i.ID = Customers.ID

This is working fine.  I however have an additional requirement:  If the i.status value is 'Offline' then I would also like to update the Customers table 'Active' field to 'NO'.

How can I do this in my SQL code?

Thanks

Chris
ASKER CERTIFIED SOLUTION
Avatar of chapmandew
chapmandew
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial