Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
T-SQL Newbie creating trigger
Message
 
 
To
All
General information
Forum:
Microsoft SQL Server
Category:
Other
Title:
T-SQL Newbie creating trigger
Miscellaneous
Thread ID:
01031991
Message ID:
01031991
Views:
56
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)
Next
Reply
Map
View

Click here to load this message in the networking platform