I am very new to SQL Server and I need to create a trigger that update the (Company nvarchar) record in the WorkOrders table when the (Company nvarchar) record in the Clients table is change
CREATE TRIGGER updClients
ON Clients
FOR update AS
Set nocount on
Update WorkOrders Set Company=i.Company
From WorkOrders w Inner Join inserted i
On w.ClientId=i.ClientID
Terry L. Broadbent FAQ183-874 contains tips for posting questions in these forums.
NOTE: Reference to the FAQ is not directed at any individual.
Alter Trigger Customers_UTrigger
On dbo.Customers
FOR UPDATE
AS
IF UPDATE(Company)
BEGIN
UPDATE(WorkOrders)
SET WorkOrders.Company=inserted.Company
FROM WorkOrders, deleted, inserted
WHERE deleted.WorkOrders=WorkOrders.Company
END
Remove the parentheses around the table name. The line should read UPDATE WorkOrders. Terry L. Broadbent FAQ183-874 contains tips for posting questions in these forums.
NOTE: Reference to the FAQ is not directed at any individual.
You have used the table name incorrectly in the Where clause. You should have a column name.
WHERE deleted.WorkOrders=WorkOrders.Company
NOTE: In addition, you should have criteria to JOIN WorkTables to the inserted table as well as the deleted table. Terry L. Broadbent FAQ183-874 contains tips for posting questions in these forums.
NOTE: Reference to the FAQ is not directed at any individual.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.