Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Update Trigger

Author  Topic 

jrockfl
Posting Yak Master

223 Posts

Posted - 2008-01-19 : 15:01:14
I want to update User_Def with the current value from Sales_PTD before that column is updated. How does this trigger look? It appears to work fine, just wanted a second set of eyes to look over it.

CREATE TRIGGER UpdateSales
ON Sales
FOR UPDATE
AS
BEGIN
UPDATE Sales
SET User_Def = d.Sales_PTD
FROM deleted d
INNER JOIN inserted i on i.id = d.id
WHERE d.id = sales.id
END

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2008-01-19 : 15:33:17
that looks fine. only modification i might suggest is to join to sales, may be better if more than one record is updated

CREATE TRIGGER UpdateSales
ON Sales
FOR UPDATE
AS
BEGIN
UPDATE Sales
SET User_Def = d.Sales_PTD
FROM deleted d
INNER JOIN inserted i on i.id = d.id
INNER JOIN Sales s
On S.id = d.id
--WHERE d.id = sales.id
END
Go to Top of Page

jrockfl
Posting Yak Master

223 Posts

Posted - 2008-01-19 : 16:04:44
Thanks russel,
I will give that a try
Go to Top of Page
   

- Advertisement -