Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

New Guy......Simple update trigger question??????

Status
Not open for further replies.

ind

Programmer
Mar 9, 2000
121
US
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

Please help
 
Check SQL BOL for complete explanation of Triggers including examples.


Simple example:

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.
 
This is syntax:

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

I keep geeting this error message:

ADO error: Line 7: Incorrect syntax near '('.

What's wrong???????
 

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.
 
Now I get:

Invalid column naem 'WorkOrders'.
 

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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top