Advertisement
Guest User

Untitled

a guest
Sep 22nd, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. --7. RETURN A FILM --
  2. CREATE TRIGGER ReturnAFilm
  3. ON Receipt_Film
  4. AFTER INSERT
  5. AS
  6. DECLARE @RentID INT
  7. DECLARE @FilmID INT
  8. SELECT @RentID = RentID, @FilmID = FilmID FROM INSERTED
  9. DECLARE @Amount FLOAT
  10. DECLARE @Quantity INT
  11. DECLARE @MachineID INT
  12. SELECT @Amount = PricePerDay * DATEDIFF(DAY, RentDate, ReturnDate), @Quantity = Quantity, @MachineID = Receipt.MachineID FROM Receipt
  13. INNER JOIN Receipt_Film
  14. ON Receipt_Film.ReceiptID = Receipt.ID
  15. INNER JOIN Rent
  16. ON Rent.ID = Receipt_Film.RentID
  17. INNER JOIN Rent_Film
  18. ON Rent_Film.FilmID = Receipt_Film.FilmID AND Rent_Film.RentID = Receipt_Film.RentID
  19. INNER JOIN Film
  20. ON Film.ID = Rent_Film.FilmID
  21. WHERE Receipt_Film.RentID = @RentID AND Receipt_Film.FilmID = @FilmID
  22. UPDATE Receipt_Film SET Amount = @Amount
  23. WHERE RentID = @RentID AND FilmID = @FilmID
  24. UPDATE Machine_Film SET NumberOfFilms = NumberOfFilms + @Quantity
  25. WHERE MachineID = @MachineID AND FilmID = @FilmID
  26.  
  27. GO
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement