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
|
CREATE TRIGGER PassageBF ON [dbo].[F_DOCLIGNE]
FOR UPDATE
AS
DECLARE @PasseBF NUMERIC(13), @Qte NUMERIC(13),@Type SMALLINT,@Piece VARCHAR(9),@DL_No INTEGER,@QteAvant NUMERIC(13),@Test INTEGER
SELECT @Type=DO_Type,@PasseBF=PassageBF,@Qte=DL_Qte,@Piece=DO_Piece,@DL_No=DL_No FROM Inserted
SELECT @QteAvant=DL_Qte FROM Deleted
Set @Test=0
IF @Type=25
BEGIN
WHILE @Test=0
BEGIN
DECLARE curseurOF CURSOR
FOR SELECT DL_Qte FROM F_DOCLIGNE WHERE DL_No<>@DL_No AND DO_Piece=@Piece
Open curseurOF
FETCH NEXT FROM curseurOF
WHILE @@FETCH_STATUS = 0
BEGIN
Set @Test=1
UPDATE F_DOCLIGNE SET DL_Qte=(DL_Qte*@Qte)/@QteAvant FROM F_DOCLIGNE WHERE DL_No<>@DL_No AND DO_Piece = @Piece
COMMIT
FETCH NEXT FROM CurseurOF;
END
CLOSE curseurOF
DEALLOCATE curseurOF
END
END |
Partager