"m3ckon" <an*******@devdex.com> wrote in message
news:41**********************@news.newsgroups.ws.. .
Hi there,
I'm a little stuck and would like some help
I need to create an update trigger which will run an update query on
another table.
However, What I need to do is update the other table with the changed
record value from the table which has the trigger.
Can someone please show me how this is done please??
I can write both queries, but am unsure as to how to get the value of
the changed record for use in my trigger???
Please help
M3ckon
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
I'm not entirely sure, but I guess you want something like this:
create trigger MyTrig on MyTable
after update
as
begin
if @@rowcount = 0 return
update dbo.MyTable2
set col1 = i.col1
from inserted i
join dbo.MyTable2 mt
on i.PrimaryKey = mt.PrimaryKey
end
This assumes that MyTable2 has the same primary key as MyTable. Another
possibility to consider might be cascading referential integrity, if that's
appropriate for your situation - see Books Online.
If this doesn't help, please post the full CREATE TABLE statements for both
tables.
Simon