Ullas
Ullas

Reputation: 11556

Update a table after insert data on another table using trigger

I have to update a column in table_b when a row inserted to table_a.

Query

CREATE TRIGGER trg_Update
ON table_a FOR INSERT
AS 
UPDATE table_b
SET Sold_Qty=inserted.qty
WHERE OrdNo=inserted.OrdNo;

I am getting the following error.

Msg 4104, Level 16, State 1, Procedure trg_Update, Line 6
The multi-part identifier "inserted.OrdNo" could not be bound.

Upvotes: 0

Views: 133

Answers (1)

Giorgos Betsos
Giorgos Betsos

Reputation: 72205

Try this in place of the UPDATE query:

UPDATE table_b
SET Sold_Qty=inserted.qty
FROM table_b b
INNER JOIN inserted ON b.OrdNo=inserted.OrdNo;

Upvotes: 2

Related Questions