Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
T-SQL Newbie creating trigger
Message
 
À
Tous
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Autre
Titre:
T-SQL Newbie creating trigger
Divers
Thread ID:
01031991
Message ID:
01031991
Vues:
55
This trigger is supposed to ajust the quantity in the IN_ItemEntrepot table.
The logic behind it is: when updating the received quantity in the IN_ReceptionDetail table the trigger should substract the actual quantity and add the new inserted quantity.

So if in hand is 100


updating the received quantity from 50 to 75 should do the following:

100 -50 + 75 = 125

What I think is really happening is 100 -75 +75 = 100

What is wrong here?
CREATE TRIGGER [ReceptionDetail$UPDATE] ON [dbo].[IN_ReceptionDetail] 
FOR UPDATE
AS
IF UPDATE(nQuantiteRecu)
  BEGIN
    UPDATE  IN_ItemEntrepot SET  nEnMainQuantite =  nEnMainQuantite -   
    IN_ReceptionDetail.nQuantiteRecu + INSERTED.nQuantiteRecu FROM  
    IN_ItemEntrepot 
    JOIN INSERTED ON  INSERTED.fk_Item =  IN_ItemEntrepot.fk_Item AND  
    INSERTED.fk_Entrepot =  IN_ItemEntrepot.fk_Entrepot
    JOIN IN_ReceptionDetail ON IN_ReceptionDetail.ID =  INSERTED.ID
  END
Luc Nadeau
lnadeau@neova.ca

"the theory, it is when all is known and that nothing works. The practice, it is when all works and that nobody knows why." - Albert Einstein (Nobel of physique 1921)
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform