Trigger et If

cs_Son_of_the_Sun Messages postés 49 Date d'inscription jeudi 26 mai 2005 Statut Membre Dernière intervention 13 août 2006 - 19 avril 2006 à 02:22
cs_Son_of_the_Sun Messages postés 49 Date d'inscription jeudi 26 mai 2005 Statut Membre Dernière intervention 13 août 2006 - 20 avril 2006 à 23:36
Bonjour, je vous expose mon problème.

J'aimerais effectuer deux instructions sur le même 'If', et il me génère une erreur de syntaxe au niveau du 'Else'



CREATE TRIGGER majParti on ELIRE instead of insert

as

BEGIN



DECLARE @idParti int, @occ int, @dateMaj datetime, @idElect int, @dateElec datetime

SELECT @idParti IDPARTI, @idElect IDCITOYEN, @dateElec = date FROM INSERTED

SELECT @dateMaj =max(DATE)

FROM ELIRE

WHERE IDPARTI = @idParti

insert into elire values(@idParti,@idElect,@dateElec)

IF MONTH(@dateMaj) month(@dateElec) and YEAR(@dateMaj) year(@dateElec)

/* Instruction n°1*/ SELECT
@occOccurrences FROM SONDAGE WHERE idParti @idParti AND
month(dateMaj) MONTH(@dateMaj) and year(dateMaj) YEAR(@dateMaj)

/* Instruction n°2*/ UPDATE
SONDAGE Set Occurrences @occ+1 WHERE idParti @idParti AND
month(dateMaj) month(@dateMaj) and year(dateMaj) YEAR(@dateMaj)

ELSE



INSERT into SONDAGE values (@idParti, 1, @dateElec)

END





Pouvez-vous m'aider si possible?

Merci d'avance

2 réponses

Mindiell Messages postés 558 Date d'inscription jeudi 25 juillet 2002 Statut Membre Dernière intervention 5 septembre 2007 1
20 avril 2006 à 10:19
essaye un BEGIN END pour voir :
IF test
BEGIN
instruction 1
instruction 2
END
ELSE
instruction 1
0
cs_Son_of_the_Sun Messages postés 49 Date d'inscription jeudi 26 mai 2005 Statut Membre Dernière intervention 13 août 2006
20 avril 2006 à 23:36
Eh bien ta solution semble fonctionner, bien que mon problème pas résolu... Apparemment j'ai du me planter quelque part car le programme ne rentre pas dans la condition...
0
Rejoignez-nous