Aproposito tuve que hacer el trigger dos veces ya que en el momento de hacer algunos cambios en las tablas tambien tuve que cambiar el stored procedure que creaba las tablas de mi base de datos y lo modifique y cuando iba a probarlo entonces tuve que limpiar mi base de datos y en ese toque tambien perdi mi Trigger.... asi que tuve que volver a hacerlo desde el inicio porque no lo tenia respaldado en ningun lugar...🤦🏽♂
En fin, acontinuacion el codigo del trigger:
CREATE TRIGGER [dbo].[Estados] ON [dbo].[CuentaAhorro]
AFTER INSERT
AS
BEGIN
-- SET NOCOUNT ON added to
prevent extra result sets from
-- interfering with SELECT
statements.
SET NOCOUNT ON;
declare @idCuenta int;
declare @Fecha date;
declare @FechaFin date;
declare @SaldoI money;
declare @NumCuenta nvarchar(50);
Select @idCuenta = NewCA.id from inserted NewCA;
Select @Fecha = NewCA.FechaCreacion
from inserted NewCA;
Select @SaldoI = NewCA.Saldo from inserted NewCA;
Select @NumCuenta = NewCA.Numero_Cuenta
from inserted NewCA;
set @FechaFin = DATEADD(MONTH, 1, @Fecha);
--CAlCULO DE INTERESES
declare @interes money;
declare @idtipo int = (Select CA.idTipoCuentaAhorro from CuentaAhorro CA where CA.Numero_Cuenta = @NumCuenta);
declare @Saldomin money= (Select TCA.Saldo_Minimo from TipoCuentaAhorro TCA where TCA.id = @idtipo);
declare @tasaInteres int= (Select TCA.Tasa_Interes_Anualizada from TipoCuentaAhorro TCA where TCA.id = @idtipo);
declare
@CargoServicio money= (Select TCA.Monto_Mensual_Cars_Servicio from TipoCuentaAhorro TCA where TCA.id = @idtipo)
set @interes = (@Saldomin * @tasaInteres)/@CargoServicio;
------------------------------INSERCION---------------------------------------
INSERT INTO dbo.EstadoCuenta(idCuenta, Fecha_Inicio, Fecha_Final, Saldo_Inicial,
Saldo_Final, Intereses, Numero_Cuenta)
VALUES(@idCuenta, @Fecha, @FechaFin, @SaldoI, @SaldoI, @interes, @NumCuenta)
En este dia debido a la gran cantidad de inconvenientes que tuve trabaje unas 3,1 horas
No hay comentarios:
Publicar un comentario