Problema con Trigger for Update
Publicado por Regina (9 intervenciones) el 02/04/2007 18:09:54
HOLA ESTOY DISEÑANDO UN TRIGGER EN QUE MONITOREE UNA TABLA Y EN CASO DE QUE HAYA CAMBIOS EN ELLA REGISTRE EN OTRA TABLA LO ACONTECIDO... YA HACE LA MITAD... PERO CUANDO SE TRATA DE VERIFICAR LAS CONDICIONES PARA SABER CUÁLES CAMPOS FUERON LOS AFECTADOS... NO ENTRA A NINGUNA DE ELLAS... YA HICE EL QUERY APARTE Y LOS RESULTADOS QUE ME ARROJA SON LOS MISMOS PARA AMBAS TABLAS... LO CUAL SIGNIFICA QUE NO LOGRO QUEDARME CON EL VALOR ORIGINAL QUE LA TABLA TENÍA... Y COMO LA CONDICIÉN ES SI LOS DATOS SON DIFERENTES PUES NO ENTRA ... ALGUIÉN TIENE IDEA DE CÓMO PUEDO SOLUCIONAR ESTO??
ESTOY TRABAJANDO CON SQL 7... NO PUEDO UTILIZAR EL IF UPDATE NI PUEDO HACER EL TRIGGER BEFORE UPDATE :s
CREATE TRIGGER trigger_upd_tcad_Prueba ON tcad_Prueba BEFORE UPDATE AS
DECLARE @clave int
SET @clave = (SELECT (claId) FROM Inserted)
DECLARE @mensaje varchar(100)
DECLARE @consec int
SET @consec = (SELECT MAX (cnsc_modif) FROM tcad_Modificados)+1
BEGIN
IF ((select (inserted.nombre) from inserted,tcad_Prueba where inserted.claId = tcad_Prueba.claId) <> (select (tcad_Prueba.nombre) from inserted, tcad_Prueba WHERE inserted.claId = tcad_Prueba.claId))
SET @mensaje = @mensaje+'[nombre]'
IF ((select (inserted.Apellidos) from inserted,tcad_Prueba where inserted.claId = tcad_Prueba.claId) <> (select (tcad_Prueba.Apellidos) from inserted, tcad_Prueba WHERE inserted.claId = tcad_Prueba.claId))
SET @mensaje = @mensaje+', '+'Apellidos'
IF ((select (inserted.fechaNacimiento) from inserted,tcad_Prueba where inserted.claId = tcad_Prueba.claId) <> (select (tcad_Prueba.fechaNacimiento) from inserted, tcad_Prueba WHERE inserted.claId = tcad_Prueba.claId))
SET @mensaje = @mensaje+', '+'fechaNacimiento'
IF ((select (inserted.ingresoMensual) from inserted,tcad_Prueba where inserted.claId = tcad_Prueba.claId) <> (select (tcad_Prueba.ingresoMensual) from inserted, tcad_Prueba WHERE inserted.claId = tcad_Prueba.claId))
SET @mensaje = @mensaje+', '+'ingresoMensual'
IF ((select (inserted.Casado) from inserted,tcad_Prueba where inserted.claId = tcad_Prueba.claId) <> (select (tcad_Prueba.Casado) from inserted, tcad_Prueba WHERE inserted.claId = tcad_Prueba.claId))
SET @mensaje = @mensaje+', '+'Casado'
INSERT INTO tcad_Modificados
(
cnsc_modif,
cnsc_original,
fec_hora_modif,
tipo_modif,
colum_modif,
status_mail
)
VALUES
(
@consec,
@clave,
getdate(),
'Actualización',
@mensaje,
0
)
RETURN
END
ESTOY TRABAJANDO CON SQL 7... NO PUEDO UTILIZAR EL IF UPDATE NI PUEDO HACER EL TRIGGER BEFORE UPDATE :s
CREATE TRIGGER trigger_upd_tcad_Prueba ON tcad_Prueba BEFORE UPDATE AS
DECLARE @clave int
SET @clave = (SELECT (claId) FROM Inserted)
DECLARE @mensaje varchar(100)
DECLARE @consec int
SET @consec = (SELECT MAX (cnsc_modif) FROM tcad_Modificados)+1
BEGIN
IF ((select (inserted.nombre) from inserted,tcad_Prueba where inserted.claId = tcad_Prueba.claId) <> (select (tcad_Prueba.nombre) from inserted, tcad_Prueba WHERE inserted.claId = tcad_Prueba.claId))
SET @mensaje = @mensaje+'[nombre]'
IF ((select (inserted.Apellidos) from inserted,tcad_Prueba where inserted.claId = tcad_Prueba.claId) <> (select (tcad_Prueba.Apellidos) from inserted, tcad_Prueba WHERE inserted.claId = tcad_Prueba.claId))
SET @mensaje = @mensaje+', '+'Apellidos'
IF ((select (inserted.fechaNacimiento) from inserted,tcad_Prueba where inserted.claId = tcad_Prueba.claId) <> (select (tcad_Prueba.fechaNacimiento) from inserted, tcad_Prueba WHERE inserted.claId = tcad_Prueba.claId))
SET @mensaje = @mensaje+', '+'fechaNacimiento'
IF ((select (inserted.ingresoMensual) from inserted,tcad_Prueba where inserted.claId = tcad_Prueba.claId) <> (select (tcad_Prueba.ingresoMensual) from inserted, tcad_Prueba WHERE inserted.claId = tcad_Prueba.claId))
SET @mensaje = @mensaje+', '+'ingresoMensual'
IF ((select (inserted.Casado) from inserted,tcad_Prueba where inserted.claId = tcad_Prueba.claId) <> (select (tcad_Prueba.Casado) from inserted, tcad_Prueba WHERE inserted.claId = tcad_Prueba.claId))
SET @mensaje = @mensaje+', '+'Casado'
INSERT INTO tcad_Modificados
(
cnsc_modif,
cnsc_original,
fec_hora_modif,
tipo_modif,
colum_modif,
status_mail
)
VALUES
(
@consec,
@clave,
getdate(),
'Actualización',
@mensaje,
0
)
RETURN
END
Valora esta pregunta


0