Monday, March 26, 2012

on Insert, then Update Tigger Help

when a record is inserted into tNTS, I need the columnseq_numupdated with the value of the columnid(it's the PK)

can someone help me with my tigger:

CREATE TRIGGER updateNewSeq
ON dbo.tNTS
FOR INSERT
AS

update tNTS
(
set seq_num =tNTS
)
SELECT
NTS_id
FROM INSERTED

cheersYour update statement looks wierd.

Use as an example:

 update titleauthor
set title_id = inserted.title_id
from titleauthor, deleted, inserted
where deleted.title_id = titleauthor.title_id
|||I tried:

CREATE TRIGGER [updateSeqNum] ON [dbo].[tNTS]
FOR INSERT
AS
update tNTS
set seq_num = NTS_id
from inserted

got error: error 209 ambigious column name: NTS_id

NTS_id is the pk i'm trying to copy to column seq_num after the record is inserted|||You need a where statement for starters so it knows where to actually update.|||

update tNTS

set seq_num=i.NTS_id

from tNTS

JOIN inserted i ON (tNTS.id=i.id)

|||thanks motley, it worked

No comments:

Post a Comment