Quiero que mi trigger actúe siempre y cuando se cumpla esta condición "IF(#CursorUpdate.Key5 ='P001') " pero tengo errores al ejecutar , soy nuevo en el tema de los Triggers.
USE [EpicorTest905]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create trigger [dbo].[tgEpicor_RES1_UD33_Impresion0]
on [dbo].[UD33]
for update
as
if
Update(ShortChar01) or
Update(ShortChar02) or
Update(ShortChar03) or
UPDATE(ShortChar04) or
UPDATE(ShortChar11) or
UPDATE(ShortChar12) or
UPDATE(ShortChar09) or
UPDATE(ShortChar10) or
UPDATE(ShortChar14) or
UPDATE(Number01) or
UPDATE(Number02) or
update(Number03) or
update(Number04) or
update(CheckBox01) or
update(ShortChar05) or
update(ShortChar06) or
update(ShortChar07) or
update(ShortChar08) or
update(Character05) or
update(Number05) or
update(Number06) or
update(Number07) or
update(Number08) or
update(Number09) or
update(Number10) or
update(Number11) or
update(Number12) or
update(Number13) or
update(Number14) or
update(Number15) or
update(Number16) or
update(Number17) or
update(Number18) or
UPDATE(ShortChar16) or
UPDATE(ShortChar17) or
update(CheckBox03) or
UPDATE(ShortChar15) or
update(Character01) or
update(Character03) or
update(Character02) or
update(Character04) or
update(Character06)
begin
Select
i.PROGRESS_RECID as correlativo,
d.ShortChar01 as CarasLadosCodigo,
d.ShortChar02 as CarasLadosDescripcion,
d.ShortChar03 as TipoImpresionCodigo,
d.ShortChar04 as TipoImpresionDescripcion,
d.ShortChar11 as MaterialCodigo,
d.ShortChar12 as MaterialDescripcion,
d.ShortChar09 as UbicacionCodigo,
d.ShortChar10 as UbicacionDescripcion,
d.ShortChar14 as TipoBanda,
d.Number01 as NumeroColores,
d.Number02 as Cilindros,
d.Number03 as CantidadBandas,
d.Number04 as Repeticiones,
d.CheckBox01 as PonerLogoResinplast,
d.ShortChar05 as TextoLegal,
d.ShortChar06 as UnidadFrecuencia,
d.ShortChar07 as UnidadAnchoMaterial,
d.ShortChar08 as UnidadEspesorMaterial,
d.Character05 as Observaciones,
d.Number05 as Frecuencia,
d.Number06 as AnchoMaterial,
d.Number07 as EspesorMaterial,
d.Number08 as GramajeMaterialm2,
d.Number09 as GramajeTinta,
d.Number10 as GramajeTotal,
d.Number11 as AnchoFotoCelula_mm,
d.Number12 as LargoFotoCelula_mm,
d.Number13 as DistanciaCorteFotocelula_mm,
d.Number14 as Sentido,
d.Number15 as FactorKgMillar,
d.Number16 as AnchoBanda_mm,
d.Number17 as Refile_mm,
d.Number18 as AnchoRequerido,
d.ShortChar16 as ColorCodigo,
d.ShortChar17 as ColorDescripcion,
d.CheckBox03 as IndRebobinadoEnLinea,
d.ShortChar15 as TipoTintaResistenciaCodigo,
d.Character01 as TipoTintaResistenciaDescripcion,
d.Character03 as ColoresCodigo,
d.Character02 as ColoresDescripcion,
d.Character04 as ColoresViscocidad,
d.Character06 as CodigoDeBarra,
i.ShortChar01,
i.ShortChar02,
i.ShortChar03,
i.ShortChar04,
i.ShortChar11,
i.ShortChar12,
i.ShortChar09,
i.ShortChar10,
i.ShortChar14,
i.Number01,
i.Number02,
i.Number03,
i.Number04,
i.CheckBox01,
i.ShortChar05,
i.ShortChar06,
i.ShortChar07,
i.ShortChar08,
i.Character05,
i.Number05,
i.Number06,
i.Number07,
i.Number08,
i.Number09,
i.Number10,
i.Number11,
i.Number12,
i.Number13,
i.Number14,
i.Number15,
i.Number16,
i.Number17,
i.Number18,
i.ShortChar16,
i.ShortChar17,
i.CheckBox03,
i.ShortChar15,
i.Character01,
i.Character03,
i.Character02,
i.Character04,
i.Character06,
i.Key1 ,
i.Key2 ,
i.Key3 ,
i.Key4 ,
i.Key5 ,
into #CursorUpdate
from deleted as d
join inserted as i on d.PROGRESS_RECID=i.PROGRESS_RECID
IF(#CursorUpdate.Key5 ='P001')
BEGIN
declare @UsuarioModificacion varchar(50)
set @UsuarioModificacion = (select Character05 from UD32 (nolock)
WHERE Company='C01' and Key1='0120400092' and Key2='1')
if exists(select * from #CursorUpdate where CarasLadosCodigo <> ShortChar01)
insert into RES1_LogAuditoria
select Key1,Key2,Key3,Key4,Key5,
'UD33_Impresion0','ShortChar01','FichaTecnica','UD33_Impresion0-ShortChar01',correlativo,
CarasLadosCodigo ,ShortChar01,@UsuarioModificacion,GETDATE(),'Editado'
from #CursorUpdate
if exists(select * from #CursorUpdate where CarasLadosDescripcion <> ShortChar02)
insert into RES1_LogAuditoria
select Key1,Key2,Key3,Key4,Key5,
'UD33_Impresion0','ShortChar02','FichaTecnica','UD33_Impresion0-ShortChar02',correlativo,
CarasLadosDescripcion ,ShortChar02,@UsuarioModificacion,GETDATE(),'Editado'
from #CursorUpdate
if exists(select * from #CursorUpdate where TipoImpresionCodigo <> ShortChar03)
insert into RES1_LogAuditoria
select Key1,Key2,Key3,Key4,Key5,
'UD33_Impresion0','ShortChar03','FichaTecnica','UD33_Impresion0-ShortChar03',correlativo,
TipoImpresionCodigo ,ShortChar03,@UsuarioModificacion,GETDATE(),'Editado'
from #CursorUpdate
if exists(select * from #CursorUpdate where TipoImpresionDescripcion <> ShortChar04)
insert into RES1_LogAuditoria
select Key1,Key2,Key3,Key4,Key5,
'UD33_Impresion0','ShortChar04','FichaTecnica','UD33_Impresion0-ShortChar04',correlativo,
TipoImpresionDescripcion ,ShortChar04,@UsuarioModificacion,GETDATE(),'Editado'
from #CursorUpdate
if exists(select * from #CursorUpdate where MaterialCodigo <> ShortChar11)
insert into RES1_LogAuditoria
select Key1,Key2,Key3,Key4,Key5,
'UD33_Impresion0','ShortChar11','FichaTecnica','UD33_Impresion0-ShortChar11',correlativo,
MaterialCodigo ,ShortChar11,@UsuarioModificacion,GETDATE(),'Editado'
from #CursorUpdate
End
if exists(select * from #CursorUpdate where MaterialDescripcion <> ShortChar12)
insert into RES1_LogAuditoria
select Key1,Key2,Key3,Key4,Key5,
'UD33_Impresion0','ShortChar12','FichaTecnica','UD33_Impresion0-ShortChar12',correlativo,
MaterialDescripcion ,ShortChar12,@UsuarioModificacion,GETDATE(),'Editado'
from #CursorUpdate
if exists(select * from #CursorUpdate where UbicacionCodigo <> ShortChar09)
insert into RES1_LogAuditoria
select Key1,Key2,Key3,Key4,Key5,
'UD33_Impresion0','ShortChar09','FichaTecnica','UD33_Impresion0-ShortChar09',correlativo,
UbicacionCodigo ,ShortChar09,@UsuarioModificacion,GETDATE(),'Editado'
from #CursorUpdate
if exists(select * from #CursorUpdate where UbicacionDescripcion <> ShortChar10)
insert into RES1_LogAuditoria
select Key1,Key2,Key3,Key4,Key5,
'UD33_Impresion0','ShortChar10','FichaTecnica','UD33_Impresion0-ShortChar10',correlativo,
UbicacionDescripcion ,ShortChar10,@UsuarioModificacion,GETDATE(),'Editado'
from #CursorUpdate
if exists(select * from #CursorUpdate where TipoBanda <> ShortChar14)
insert into RES1_LogAuditoria
select Key1,Key2,Key3,Key4,Key5,
'UD33_Impresion0','ShortChar14','FichaTecnica','UD33_Impresion0-ShortChar14',correlativo,
TipoBanda ,ShortChar14,@UsuarioModificacion,GETDATE(),'Editado'
from #CursorUpdate
if exists(select * from #CursorUpdate where NumeroColores <> Number01)
insert into RES1_LogAuditoria
select Key1,Key2,Key3,Key4,Key5,
'UD33_Impresion0','Number01','FichaTecnica','UD33_Impresion0-Number01',correlativo,
NumeroColores ,Number01,@UsuarioModificacion,GETDATE(),'Editado'
from #CursorUpdate
if exists(select * from #CursorUpdate where Cilindros <> Number02)
insert into RES1_LogAuditoria
select Key1,Key2,Key3,Key4,Key5,
'UD33_Impresion0','Number02','FichaTecnica','UD33_Impresion0-Number02',correlativo,
Cilindros ,Number02,@UsuarioModificacion,GETDATE(),'Editado'
from #CursorUpdate
if exists(select * from #CursorUpdate where CantidadBandas <> Number03)
insert into RES1_LogAuditoria
select Key1,Key2,Key3,Key4,Key5,
'UD33_Impresion0','Number03','FichaTecnica','UD33_Impresion0-Number03',correlativo,
CantidadBandas ,Number03,@UsuarioModificacion,GETDATE(),'Editado'
from #CursorUpdate
if exists(select * from #CursorUpdate where Repeticiones <> Number04)
insert into RES1_LogAuditoria
select Key1,Key2,Key3,Key4,Key5,
'UD33_Impresion0','Number04','FichaTecnica','UD33_Impresion0-Number04',correlativo,
Repeticiones ,Number04,@UsuarioModificacion,GETDATE(),'Editado'
from #CursorUpdate
if exists(select * from #CursorUpdate where PonerLogoResinplast <> CheckBox01)
insert into RES1_LogAuditoria
select Key1,Key2,Key3,Key4,Key5,
'UD33_Impresion0','CheckBox01','FichaTecnica','UD33_Impresion0-CheckBox01',correlativo,
PonerLogoResinplast ,CheckBox01,@UsuarioModificacion,GETDATE(),'Editado'
from #CursorUpdate
if exists(select * from #CursorUpdate where TextoLegal <> ShortChar05)
insert into RES1_LogAuditoria
select Key1,Key2,Key3,Key4,Key5,
'UD33_Impresion0','ShortChar05','FichaTecnica','UD33_Impresion0-ShortChar05',correlativo,
TextoLegal ,ShortChar05,@UsuarioModificacion,GETDATE(),'Editado'
from #CursorUpdate
if exists(select * from #CursorUpdate where UnidadFrecuencia <> ShortChar06)
insert into RES1_LogAuditoria
select Key1,Key2,Key3,Key4,Key5,
'UD33_Impresion0','ShortChar06','FichaTecnica','UD33_Impresion0-ShortChar06',correlativo,
UnidadFrecuencia ,ShortChar06,@UsuarioModificacion,GETDATE(),'Editado'
from #CursorUpdate
if exists(select * from #CursorUpdate where UnidadAnchoMaterial <> ShortChar07)
insert into RES1_LogAuditoria
select Key1,Key2,Key3,Key4,Key5,
'UD33_Impresion0','ShortChar07','FichaTecnica','UD33_Impresion0-ShortChar07',correlativo,
UnidadAnchoMaterial ,ShortChar07,@UsuarioModificacion,GETDATE(),'Editado'
from #CursorUpdate
if exists(select * from #CursorUpdate where UnidadEspesorMaterial <> ShortChar08)
insert into RES1_LogAuditoria
select Key1,Key2,Key3,Key4,Key5,
'UD33_Impresion0','ShortChar08','FichaTecnica','UD33_Impresion0-ShortChar08',correlativo,
UnidadEspesorMaterial ,ShortChar08,@UsuarioModificacion,GETDATE(),'Editado'
from #CursorUpdate
if exists(select * from #CursorUpdate where UnidadEspesorMaterial <> ShortChar08)
insert into RES1_LogAuditoria
select Key1,Key2,Key3,Key4,Key5,
'UD33_Impresion0','ShortChar08','FichaTecnica','UD33_Impresion0-Character05',correlativo,
UnidadEspesorMaterial ,Character05,@UsuarioModificacion,GETDATE(),'Editado'
from #CursorUpdate
if exists(select * from #CursorUpdate where Observaciones <> Character05)
insert into RES1_LogAuditoria
select Key1,Key2,Key3,Key4,Key5,
'UD33_Impresion0','Character05','FichaTecnica','UD33_Impresion0-Character05',correlativo,
Observaciones ,Character05,@UsuarioModificacion,GETDATE(),'Editado'
from #CursorUpdate
if exists(select * from #CursorUpdate where Frecuencia <> Number05)
insert into RES1_LogAuditoria
select Key1,Key2,Key3,Key4,Key5,
'UD33_Impresion0','Number05','FichaTecnica','UD33_Impresion0-Number05',correlativo,
Frecuencia ,Number05,@UsuarioModificacion,GETDATE(),'Editado'
from #CursorUpdate
if exists(select * from #CursorUpdate where AnchoMaterial <> Number06)
insert into RES1_LogAuditoria
select Key1,Key2,Key3,Key4,Key5,
'UD33_Impresion0','Number06','FichaTecnica','UD33_Impresion0-Number06',correlativo,
AnchoMaterial ,Number06,@UsuarioModificacion,GETDATE(),'Editado'
from #CursorUpdate
if exists(select * from #CursorUpdate where EspesorMaterial <> Number07)
insert into RES1_LogAuditoria
select Key1,Key2,Key3,Key4,Key5,
'UD33_Impresion0','Number07','FichaTecnica','UD33_Impresion0-Number07',correlativo,
EspesorMaterial ,Number07,@UsuarioModificacion,GETDATE(),'Editado'
from #CursorUpdate
if exists(select * from #CursorUpdate where GramajeMaterialm2 <> Number08)
insert into RES1_LogAuditoria
select Key1,Key2,Key3,Key4,Key5,
'UD33_Impresion0','Number08','FichaTecnica','UD33_Impresion0-Number08',correlativo,
GramajeMaterialm2 ,Number08,@UsuarioModificacion,GETDATE(),'Editado'
from #CursorUpdate
if exists(select * from #CursorUpdate where GramajeTinta <> Number09)
insert into RES1_LogAuditoria
select Key1,Key2,Key3,Key4,Key5,
'UD33_Impresion0','Number09','FichaTecnica','UD33_Impresion0-Number09',correlativo,
GramajeTinta ,Number09,@UsuarioModificacion,GETDATE(),'Editado'
from #CursorUpdate
if exists(select * from #CursorUpdate where GramajeTotal <> Number10)
insert into RES1_LogAuditoria
select Key1,Key2,Key3,Key4,Key5,
'UD33_Impresion0','Number10','FichaTecnica','UD33_Impresion0-Number10',correlativo,
GramajeTotal ,Number10,@UsuarioModificacion,GETDATE(),'Editado'
from #CursorUpdate
if exists(select * from #CursorUpdate where AnchoFotoCelula_mm <> Number11)
insert into RES1_LogAuditoria
select Key1,Key2,Key3,Key4,Key5,
'UD33_Impresion0','Number11','FichaTecnica','UD33_Impresion0-Number11',correlativo,
AnchoFotoCelula_mm ,Number11,@UsuarioModificacion,GETDATE(),'Editado'
from #CursorUpdate
if exists(select * from #CursorUpdate where LargoFotoCelula_mm <> Number12)
insert into RES1_LogAuditoria
select Key1,Key2,Key3,Key4,Key5,
'UD33_Impresion0','Number12','FichaTecnica','UD33_Impresion0-Number12',correlativo,
LargoFotoCelula_mm ,Number12,@UsuarioModificacion,GETDATE(),'Editado'
from #CursorUpdate
if exists(select * from #CursorUpdate where DistanciaCorteFotocelula_mm <> Number13)
insert into RES1_LogAuditoria
select Key1,Key2,Key3,Key4,Key5,
'UD33_Impresion0','Number13','FichaTecnica','UD33_Impresion0-Number13',correlativo,
DistanciaCorteFotocelula_mm ,Number13,@UsuarioModificacion,GETDATE(),'Editado'
from #CursorUpdate
if exists(select * from #CursorUpdate where Sentido <> Number14)
insert into RES1_LogAuditoria
select Key1,Key2,Key3,Key4,Key5,
'UD33_Impresion0','Number14','FichaTecnica','UD33_Impresion0-Number14',correlativo,
Sentido ,Number14,@UsuarioModificacion,GETDATE(),'Editado'
from #CursorUpdate
if exists(select * from #CursorUpdate where FactorKgMillar <> Number15)
insert into RES1_LogAuditoria
select Key1,Key2,Key3,Key4,Key5,
'UD33_Impresion0','Number15','FichaTecnica','UD33_Impresion0-Number15',correlativo,
FactorKgMillar ,Number15,@UsuarioModificacion,GETDATE(),'Editado'
from #CursorUpdate
if exists(select * from #CursorUpdate where AnchoBanda_mm <> Number16)
insert into RES1_LogAuditoria
select Key1,Key2,Key3,Key4,Key5,
'UD33_Impresion0','Number16','FichaTecnica','UD33_Impresion0-Number16',correlativo,
AnchoBanda_mm ,Number16,@UsuarioModificacion,GETDATE(),'Editado'
from #CursorUpdate
if exists(select * from #CursorUpdate where Refile_mm <> Number17)
insert into RES1_LogAuditoria
select Key1,Key2,Key3,Key4,Key5,
'UD33_Impresion0','Number17','FichaTecnica','UD33_Impresion0-Number17',correlativo,
Refile_mm ,Number17,@UsuarioModificacion,GETDATE(),'Editado'
from #CursorUpdate
if exists(select * from #CursorUpdate where AnchoRequerido <> Number18)
insert into RES1_LogAuditoria
select Key1,Key2,Key3,Key4,Key5,
'UD33_Impresion0','Number18','FichaTecnica','UD33_Impresion0-Number18',correlativo,
AnchoRequerido ,Number18,@UsuarioModificacion,GETDATE(),'Editado'
from #CursorUpdate
if exists(select * from #CursorUpdate where ColorCodigo <> ShortChar16)
insert into RES1_LogAuditoria
select Key1,Key2,Key3,Key4,Key5,
'UD33_Impresion0','ShortChar16','FichaTecnica','UD33_Impresion0-ShortChar16',correlativo,
ColorCodigo ,ShortChar16,@UsuarioModificacion,GETDATE(),'Editado'
from #CursorUpdate
if exists(select * from #CursorUpdate where ColorDescripcion <> ShortChar17)
insert into RES1_LogAuditoria
select Key1,Key2,Key3,Key4,Key5,
'UD33_Impresion0','ShortChar17','FichaTecnica','UD33_Impresion0-ShortChar17',correlativo,
ColorDescripcion ,ShortChar17,@UsuarioModificacion,GETDATE(),'Editado'
from #CursorUpdate
if exists(select * from #CursorUpdate where IndRebobinadoEnLinea <> CheckBox03)
insert into RES1_LogAuditoria
select Key1,Key2,Key3,Key4,Key5,
'UD33_Impresion0','CheckBox03','FichaTecnica','UD33_Impresion0-CheckBox03',correlativo,
IndRebobinadoEnLinea ,CheckBox03,@UsuarioModificacion,GETDATE(),'Editado'
from #CursorUpdate
if exists(select * from #CursorUpdate where TipoTintaResistenciaCodigo <> ShortChar15)
insert into RES1_LogAuditoria
select Key1,Key2,Key3,Key4,Key5,
'UD33_Impresion0','ShortChar15','FichaTecnica','UD33_Impresion0-ShortChar15',correlativo,
TipoTintaResistenciaCodigo ,ShortChar15,@UsuarioModificacion,GETDATE(),'Editado'
from #CursorUpdate
if exists(select * from #CursorUpdate where TipoTintaResistenciaDescripcion <> Character01)
insert into RES1_LogAuditoria
select Key1,Key2,Key3,Key4,Key5,
'UD33_Impresion0','Character01','FichaTecnica','UD33_Impresion0-Character01',correlativo,
TipoTintaResistenciaDescripcion ,Character01,@UsuarioModificacion,GETDATE(),'Editado'
from #CursorUpdate
if exists(select * from #CursorUpdate where ColoresCodigo <> Character03)
insert into RES1_LogAuditoria
select Key1,Key2,Key3,Key4,Key5,
'UD33_Impresion0','Character03','FichaTecnica','UD33_Impresion0-Character03',correlativo,
ColoresCodigo ,Character03,@UsuarioModificacion,GETDATE(),'Editado'
from #CursorUpdate
if exists(select * from #CursorUpdate where ColoresDescripcion <> Character02)
insert into RES1_LogAuditoria
select Key1,Key2,Key3,Key4,Key5,
'UD33_Impresion0','Character02','FichaTecnica','UD33_Impresion0-Character02',correlativo,
ColoresDescripcion ,Character02,@UsuarioModificacion,GETDATE(),'Editado'
from #CursorUpdate
if exists(select * from #CursorUpdate where ColoresViscocidad <> Character04)
insert into RES1_LogAuditoria
select Key1,Key2,Key3,Key4,Key5,
'UD33_Impresion0','Character04','FichaTecnica','UD33_Impresion0-Character04',correlativo,
ColoresViscocidad ,Character04,@UsuarioModificacion,GETDATE(),'Editado'
from #CursorUpdate
if exists(select * from #CursorUpdate where CodigoDeBarra <> Character06)
insert into RES1_LogAuditoria
select Key1,Key2,Key3,Key4,Key5,
'UD33_Impresion0','Character06','FichaTecnica','UD33_Impresion0-Character06',correlativo,
CodigoDeBarra ,Character06,@UsuarioModificacion,GETDATE(),'Editado'
from #CursorUpdate
End
end