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 2005 Forums
 Transact-SQL (2005)
 Trigger after update

Author  Topic 

Leont
Starting Member

2 Posts

Posted - 2008-07-09 : 07:46:06
Bonjour,
J'ai un soucis avec un trigger que j'ai écrit.Voici le code:

CREATE TRIGGER ETL2UPDATE ON [Mmm].[Products]
AFTER UPDATE
AS
IF UPDATE(IsActive)
BEGIN
DECLARE @Code varchar(8)
SET @Code =(SELECT Code FROM inserted)
UPDATE [Matis].[Products]
SET Status_Id=1
WHERE Product_Code=@Code

END

IsActive et Code: sont des champs de la table [Mmm].[Products],
Status_Id: est un champ de la table [Matis].[Products]

Il ne fonctionne pas quand je fais une mise à jour sur la table [Mmm].[Products]. Je n'ai même de message d'erreur. Est-ce que quelqu'un peut me dire ce qui ne va pas?

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2008-07-09 : 07:50:34
Sorry . . . whatever language is that, i don't understand at all. I only understand T-SQL and this is the part that is wrong.

Your trigger need to handle updates in set-based

DECLARE @Code varchar(8)
SET @Code =(SELECT Code FROM inserted)

UPDATE p
SET Status_Id=1
FROM [Matis].[Products] p
INNER JOIN inserted i ON p.Product_Code = i.Code

WHERE Product_Code=@Code



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

Leont
Starting Member

2 Posts

Posted - 2008-07-09 : 08:29:06
In fact I have 2 tables,updatine a filed in the first one make fire the trigger in the seconde one. It works as I posted it.



Go to Top of Page
   

- Advertisement -