Bonjour,

J'ai un trigger sur insert, sur update. lors de l'insert cela fonctionne bien mais lors de l'update cela ne fonctionne pas!

voici le message d'erreur

No row was updated
The data in row 15 was not committed
Error Source: Microsoft.VisualStudio.DataTools
Error Message: The row value(s) updated or deleted either do not make the row unique or they alter multiple rows(2 rows)

dans mon trigger j'update la table qui a lancé le trigger, je suppose que le problème vient de la,c'est pourquoi j'ai mis une condition en début de trigger pou voir quel champs est modifié et n'agir que lorsque c'est le chamsp Date

Avez-vous une idée de comment je peux résoudre cela ?

Merci d'avance

Yoni

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
ALTER TRIGGER tr_Source_UPDATE
ON Ads
AFTER UPDATE
AS
  DECLARE @startingYearsOfService datetime
  DECLARE @Id int	
  DECLARE @year int
  DECLARE @days int
  DECLARE @statut char
  DECLARE @oldStatut char
	IF NOT UPDATE(Date)
	RETURN
  SET @startingYearsOfService = (SELECT Date FROM inserted )
  SET @Id = (SELECT IdAds FROM inserted )
  SET @oldStatut = (SELECT Contact FROM inserted )
  SET @year = abs(round((datediff(d,CURRENT_TIMESTAMP,@startingYearsOfService))/365,0,1))
  SET @days = abs(datediff(d,CURRENT_TIMESTAMP,@startingYearsOfService))
  IF @days<365
	BEGIN
		set @statut='A'
	END
  IF @year <10
	Begin
		set @statut='B'
	END
  IF @year >10
	Begin
		set @statut='C'
 
	END
 
  IF @statut <> @oldStatut
	begin
	UPDATE Ads SET [Contact]=@statut FROM Ads A INNER JOIN inserted I ON A.IdAds=I.IdAds 
	end