1
I created a Rigger to inform the fine about the delay of returning rented movies, however, when firing the Rigger once (giving an UPDATE), the field "Total Fine" does not update (only it). But when Rigger fires a second time, the reported field is updated normally. Does anyone know how to solve, if it is a problem, or if it is something normal for the case presented?
TRIGGER:
instead of update
as
declare @CodLoc int
declare @FilmeLoc int
declare @Multa float
select @CodLoc = CodLoc, @FilmeLoc = FilmeLoc, @Multa = Atraso * MultaDia
from inserted
UPDATE Locacao
SET Atraso = DATEDIFF(DAY,DtAluguel, GETDATE()), DtEntrega = GETDATE(), Situacao = 'Devolvido', MultaDia = (SELECT MultaDia FROM Filmes WHERE CodFilme = @FilmeLoc), MultaTotal = @Multa
where CodLoc = @CodLoc
update Filmes
set Disponibilidade = 'Disponivel'
where CodFilme = @FilmeLoc
And the following table:
TABLE Locacao
(
CodLoc INT IDENTITY (1,1) NOT NULL,
ClienteLoc INT FOREIGN KEY REFERENCES Clientes(CodCliente) NOT NULL,
FilmeLoc INT FOREIGN KEY REFERENCES Filmes(CodFilme) NOT NULL,
DtAluguel DATE,
DtParaEntrega DATE,
DtEntrega DATE,
Atraso INT,
Situacao VARCHAR(9), /* Alugado ou Devolvido */
MultaDia FLOAT,
MultaTotal FLOAT,
PRIMARY KEY (CodLoc)
)
However, when I do an Update, the Total Fine field only updates after a second Update:
Example:
insert into Locacao (ClienteLoc, FilmeLoc, DtAluguel, DtParaEntrega, Situacao, MultaDia)
values (2, 1, GETDATE(), DATEADD(DAY, 3, GETDATE()), 'Alugado', 2)
SELECT * FROM Locacao
CodLoc ClienteLoc FilmeLoc DtAluguel DtParaEntrega DtEntrega Atraso Situacao MultaDia MultaTotal
----------- ----------- ----------- ---------- ------------- ---------- ----------- --------- ---------------------- ----------------------
3 2 1 2018-12-09 2018-12-12 NULL NULL Alugado 2 NULL
Update 1:
update Locacao
set DtEntrega = GETDATE()
where CodLoc = 3
SELECT * FROM Locacao
CodLoc ClienteLoc FilmeLoc DtAluguel DtParaEntrega DtEntrega Atraso Situacao MultaDia MultaTotal
----------- ----------- ----------- ---------- ------------- ---------- ----------- --------- ---------------------- ----------------------
3 2 1 2018-12-09 2018-12-12 2018-12-09 0 Devolvido 2 NULL
Update 2:
update Locacao
set DtEntrega = GETDATE()
where CodLoc = 3
SELECT * FROM Locacao
CodLoc ClienteLoc FilmeLoc DtAluguel DtParaEntrega DtEntrega Atraso Situacao MultaDia MultaTotal
----------- ----------- ----------- ---------- ------------- ---------- ----------- --------- ---------------------- ----------------------
3 2 1 2018-12-09 2018-12-12 2018-12-09 0 Devolvido 2 0