    declare @nContador integer
    exec GERASEMENTE_P 'TW_IDENTIFICADOR', 7, @nContador OUTPUT
    if @nContador > 0
      update LANCHECCXA set IDLANCHEC = @nContador WHERE IDLANCHEC = (select IDLANCHEC from inserted WHERE IDLANCHEC=(@@spid*-1))
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'LANCHECCXA_U' AND type = 'TR')
   drop trigger LANCHECCXA_U
go
create trigger dbo.LANCHECCXA_U on dbo.LANCHECCXA for update as
begin
  if (select count(*) from deleted where IDLANCHEC = @@spid*-1 ) > 0
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )    SELECT getdate(), null,'UPDATE LANCHECCXA SET     FILIAL = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(FILIAL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CCUSTO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CCUSTO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    VALLANC = '+ ISNULL(LTRIM(RTRIM(CAST(VALLANC AS CHAR(254)))),0) +',    DOCUMEN = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(DOCUMEN AS CHAR(254)))),0) +'**],    CODHIST = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODHIST AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    HIST1 = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(HIST1 AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    HIST2 = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(HIST2 AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    LOCALPORTA = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(LOCALPORTA AS CHAR(254)))),0) +'**],    CONTA = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(CONTA AS CHAR(254)))),0) +'**],    NUMDOCPAG = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NUMDOCPAG AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    DATADISP = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DATADISP,20)))+''',120)','NULL')+',    NUMORD = '+ ISNULL(LTRIM(RTRIM(CAST(NUMORD AS CHAR(254)))),0) +',    CODIGO = '+ ISNULL(LTRIM(RTRIM(CAST(CODIGO AS CHAR(254)))),0) +',    TIPOATUAL = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(TIPOATUAL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    TIPOLANC = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(TIPOLANC AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    MOEDA = '+ ISNULL(LTRIM(RTRIM(CAST(MOEDA AS CHAR(254)))),0) +',    ATUALIZ = '+ ISNULL(LTRIM(RTRIM(CAST(ATUALIZ AS CHAR(254)))),0) +',    TRANSF = '+ ISNULL(LTRIM(RTRIM(CAST(TRANSF AS CHAR(254)))),0) +',    CLASSE = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CLASSE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CTB = '+ ISNULL(LTRIM(RTRIM(CAST(CTB AS CHAR(254)))),0) +',    CUS = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CUS AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    INTEGRADO = '+ ISNULL(LTRIM(RTRIM(CAST(INTEGRADO AS CHAR(254)))),0) +',    PROVIS = '+ ISNULL(LTRIM(RTRIM(CAST(PROVIS AS CHAR(254)))),0) +',    ATUALIZ2 = '+ ISNULL(LTRIM(RTRIM(CAST(ATUALIZ2 AS CHAR(254)))),0) +',    NUMDOC = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NUMDOC AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    REALFLUXO = '+ ISNULL(LTRIM(RTRIM(CAST(REALFLUXO AS CHAR(254)))),0) +',    LANCDIRET = '+ ISNULL(LTRIM(RTRIM(CAST(LANCDIRET AS CHAR(254)))),0) +',    CODUTIL = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODUTIL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    JAEMIT = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(JAEMIT AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    EXPORTADO = '+ ISNULL(LTRIM(RTRIM(CAST(EXPORTADO AS CHAR(254)))),0) +',    NUMPED = '+ ISNULL(LTRIM(RTRIM(CAST(NUMPED AS CHAR(254)))),0) +',    NUMORDFIS = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NUMORDFIS AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    IMPOGER = '+ ISNULL(LTRIM(RTRIM(CAST(IMPOGER AS CHAR(254)))),0) +',    QUANTPARCELA = '+ ISNULL(LTRIM(RTRIM(CAST(QUANTPARCELA AS CHAR(254)))),0) +',    NUMORDDEV = '+ ISNULL(LTRIM(RTRIM(CAST(NUMORDDEV AS CHAR(254)))),0) +',    RITEMPREV = '+ ISNULL(LTRIM(RTRIM(CAST(RITEMPREV AS CHAR(254)))),0) +',    RRECEBIMENTODETERCEIROS = '+ ISNULL(LTRIM(RTRIM(CAST(RRECEBIMENTODETERCEIROS AS CHAR(254)))),0) +',    DATALANC = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DATALANC,20)))+''',120)','NULL')+',    TPO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(TPO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CARENCIA = '+ ISNULL(LTRIM(RTRIM(CAST(CARENCIA AS CHAR(254)))),0) +',    CREDITODECARTAO = '+ ISNULL(LTRIM(RTRIM(CAST(CREDITODECARTAO AS CHAR(254)))),0) +',    RATOLIGACAOCONTAPAGAR = '+ ISNULL(LTRIM(RTRIM(CAST(RATOLIGACAOCONTAPAGAR AS CHAR(254)))),0) +',    RFONTEPAGADORACP = '+ ISNULL(LTRIM(RTRIM(CAST(RFONTEPAGADORACP AS CHAR(254)))),0) +',    NOMEEMITENTE = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NOMEEMITENTE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CPFCNPJEMITENTE = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CPFCNPJEMITENTE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    NUMEROBANCO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NUMEROBANCO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    NUMEROAGENCIA = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NUMEROAGENCIA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    NUMEROCONTA = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NUMEROCONTA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CMC7 = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CMC7 AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    NUMEROCHEQUE = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NUMEROCHEQUE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    IDLANCHEC = '+ ISNULL(LTRIM(RTRIM(CAST(IDLANCHEC AS CHAR(254)))),0) +',    ANALITICO = '+ ISNULL(LTRIM(RTRIM(CAST(ANALITICO AS CHAR(254)))),0) +''+  ' WHERE IDLANCHEC = '+ ISNULL(LTRIM(RTRIM(CAST((@@spid*-1) AS CHAR(254)))),0) , 'LANCHECCXA' FROM inserted
 else
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )    SELECT getdate(), null,'UPDATE LANCHECCXA SET     FILIAL = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(FILIAL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CCUSTO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CCUSTO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    VALLANC = '+ ISNULL(LTRIM(RTRIM(CAST(VALLANC AS CHAR(254)))),0) +',    DOCUMEN = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(DOCUMEN AS CHAR(254)))),0) +'**],    CODHIST = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODHIST AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    HIST1 = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(HIST1 AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    HIST2 = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(HIST2 AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    LOCALPORTA = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(LOCALPORTA AS CHAR(254)))),0) +'**],    CONTA = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(CONTA AS CHAR(254)))),0) +'**],    NUMDOCPAG = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NUMDOCPAG AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    DATADISP = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DATADISP,20)))+''',120)','NULL')+',    NUMORD = '+ ISNULL(LTRIM(RTRIM(CAST(NUMORD AS CHAR(254)))),0) +',    CODIGO = '+ ISNULL(LTRIM(RTRIM(CAST(CODIGO AS CHAR(254)))),0) +',    TIPOATUAL = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(TIPOATUAL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    TIPOLANC = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(TIPOLANC AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    MOEDA = '+ ISNULL(LTRIM(RTRIM(CAST(MOEDA AS CHAR(254)))),0) +',    ATUALIZ = '+ ISNULL(LTRIM(RTRIM(CAST(ATUALIZ AS CHAR(254)))),0) +',    TRANSF = '+ ISNULL(LTRIM(RTRIM(CAST(TRANSF AS CHAR(254)))),0) +',    CLASSE = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CLASSE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CTB = '+ ISNULL(LTRIM(RTRIM(CAST(CTB AS CHAR(254)))),0) +',    CUS = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CUS AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    INTEGRADO = '+ ISNULL(LTRIM(RTRIM(CAST(INTEGRADO AS CHAR(254)))),0) +',    PROVIS = '+ ISNULL(LTRIM(RTRIM(CAST(PROVIS AS CHAR(254)))),0) +',    ATUALIZ2 = '+ ISNULL(LTRIM(RTRIM(CAST(ATUALIZ2 AS CHAR(254)))),0) +',    NUMDOC = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NUMDOC AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    REALFLUXO = '+ ISNULL(LTRIM(RTRIM(CAST(REALFLUXO AS CHAR(254)))),0) +',    LANCDIRET = '+ ISNULL(LTRIM(RTRIM(CAST(LANCDIRET AS CHAR(254)))),0) +',    CODUTIL = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODUTIL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    JAEMIT = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(JAEMIT AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    EXPORTADO = '+ ISNULL(LTRIM(RTRIM(CAST(EXPORTADO AS CHAR(254)))),0) +',    NUMPED = '+ ISNULL(LTRIM(RTRIM(CAST(NUMPED AS CHAR(254)))),0) +',    NUMORDFIS = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NUMORDFIS AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    IMPOGER = '+ ISNULL(LTRIM(RTRIM(CAST(IMPOGER AS CHAR(254)))),0) +',    QUANTPARCELA = '+ ISNULL(LTRIM(RTRIM(CAST(QUANTPARCELA AS CHAR(254)))),0) +',    NUMORDDEV = '+ ISNULL(LTRIM(RTRIM(CAST(NUMORDDEV AS CHAR(254)))),0) +',    RITEMPREV = '+ ISNULL(LTRIM(RTRIM(CAST(RITEMPREV AS CHAR(254)))),0) +',    RRECEBIMENTODETERCEIROS = '+ ISNULL(LTRIM(RTRIM(CAST(RRECEBIMENTODETERCEIROS AS CHAR(254)))),0) +',    DATALANC = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DATALANC,20)))+''',120)','NULL')+',    TPO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(TPO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CARENCIA = '+ ISNULL(LTRIM(RTRIM(CAST(CARENCIA AS CHAR(254)))),0) +',    CREDITODECARTAO = '+ ISNULL(LTRIM(RTRIM(CAST(CREDITODECARTAO AS CHAR(254)))),0) +',    RATOLIGACAOCONTAPAGAR = '+ ISNULL(LTRIM(RTRIM(CAST(RATOLIGACAOCONTAPAGAR AS CHAR(254)))),0) +',    RFONTEPAGADORACP = '+ ISNULL(LTRIM(RTRIM(CAST(RFONTEPAGADORACP AS CHAR(254)))),0) +',    NOMEEMITENTE = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NOMEEMITENTE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CPFCNPJEMITENTE = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CPFCNPJEMITENTE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    NUMEROBANCO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NUMEROBANCO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    NUMEROAGENCIA = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NUMEROAGENCIA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    NUMEROCONTA = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NUMEROCONTA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CMC7 = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CMC7 AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    NUMEROCHEQUE = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NUMEROCHEQUE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    IDLANCHEC = '+ ISNULL(LTRIM(RTRIM(CAST(IDLANCHEC AS CHAR(254)))),0) +',    ANALITICO = '+ ISNULL(LTRIM(RTRIM(CAST(ANALITICO AS CHAR(254)))),0) +''+  ' WHERE IDLANCHEC = '+ RTRIM(CAST(IDLANCHEC as char(254))) +  ''   , 'LANCHECCXA' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'LOGECF_D' AND type = 'TR')
  drop trigger LOGECF_D
go
create trigger dbo.LOGECF_D on dbo.LOGECF for delete as
    Begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
            SELECT getdate(), null,'DELETE FROM LOGECF WHERE 
NUMEROECF = '''+ RTRIM(LTRIM(NUMEROECF)) + '''  and COO = '''+ RTRIM(LTRIM(COO)) + '''  and   CONVERT(DATETIME, LTRIM(RTRIM(CONVERT(CHAR,DATA,20))),120) =  '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DATA,20)))+''',120)','NULL'),'LOGECF' from deleted
    End
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'LOGECF_I' AND type = 'TR')
   drop trigger LOGECF_I
go
create trigger dbo.LOGECF_I on dbo.LOGECF for insert as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
    SELECT getdate(), null,'INSERT INTO LOGECF(
        NUMEROECF,    COO,    NUMEROCUPOM,    RFILIAL,    RCAIXA,    DATA,    RTIPOOPERACAO,    VALOR,    OIDOPERACAO,    RATOFINANCEIRO,    CODSEN,    NUMPEDTEF,    OIDSERIALECF)
    VALUES (
    '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NUMEROECF AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(COO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NUMEROCUPOM AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',  [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(RFILIAL AS CHAR(254)))),0) +'**],  [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(RCAIXA AS CHAR(254)))),0) +'**],'+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DATA,20 ))) +''',120)','NULL')+','+ ISNULL(LTRIM(RTRIM(CAST(RTIPOOPERACAO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALOR AS CHAR(254)))),0) +',  [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(OIDOPERACAO AS CHAR(254)))),0) +'**],  [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(RATOFINANCEIRO AS CHAR(254)))),0) +'**],'''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODSEN AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(NUMPEDTEF AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(OIDSERIALECF AS CHAR(254)))),0) +'
     '+ ')', 'LOGECF' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'LOGECF_U' AND type = 'TR')
   drop trigger LOGECF_U
go
create trigger dbo.LOGECF_U on dbo.LOGECF for update as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )    SELECT getdate(), null,'UPDATE LOGECF SET     NUMEROCUPOM = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NUMEROCUPOM AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    RFILIAL = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(RFILIAL AS CHAR(254)))),0) +'**],    RCAIXA = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(RCAIXA AS CHAR(254)))),0) +'**],    RTIPOOPERACAO = '+ ISNULL(LTRIM(RTRIM(CAST(RTIPOOPERACAO AS CHAR(254)))),0) +',    VALOR = '+ ISNULL(LTRIM(RTRIM(CAST(VALOR AS CHAR(254)))),0) +',    OIDOPERACAO = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(OIDOPERACAO AS CHAR(254)))),0) +'**],    RATOFINANCEIRO = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(RATOFINANCEIRO AS CHAR(254)))),0) +'**],    CODSEN = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODSEN AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    NUMPEDTEF = '+ ISNULL(LTRIM(RTRIM(CAST(NUMPEDTEF AS CHAR(254)))),0) +',    OIDSERIALECF = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(OIDSERIALECF AS CHAR(254)))),0) +'**]'+  ' WHERE NUMEROECF = '''+ RTRIM(NUMEROECF)  + ''' and COO = '''+ RTRIM(COO)  + ''' and   CONVERT(DATETIME, LTRIM(RTRIM(CONVERT(CHAR,DATA,20))),120) =  '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DATA,20)))+''',120)','NULL') , 'LOGECF' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'LOGECFESTORNOS_D' AND type = 'TR')
  drop trigger LOGECFESTORNOS_D
go
create trigger dbo.LOGECFESTORNOS_D on dbo.LOGECFESTORNOS for delete as
    Begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
            SELECT getdate(), null,'DELETE FROM LOGECFESTORNOS WHERE 
OID = '+ RTRIM(LTRIM(CAST(OID as char(120)))) + ' ','LOGECFESTORNOS' from deleted
    End
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'LOGECFESTORNOS_I' AND type = 'TR')
   drop trigger LOGECFESTORNOS_I
go
create trigger dbo.LOGECFESTORNOS_I on dbo.LOGECFESTORNOS for insert as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
    SELECT getdate(), null,'INSERT INTO LOGECFESTORNOS(
        OID,    RFILIAL,    ROIDREFERENCIA,    DATA,    RCAIXA,    TIPODOC,    VALOR,    CLASSIFICDOC)
    VALUES (
      [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(OID AS CHAR(254)))),0) +'**],  [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(RFILIAL AS CHAR(254)))),0) +'**],'+ ISNULL(LTRIM(RTRIM(CAST(ROIDREFERENCIA AS CHAR(254)))),0) +','+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DATA,20 ))) +''',120)','NULL')+',  [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(RCAIXA AS CHAR(254)))),0) +'**],  [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(TIPODOC AS CHAR(254)))),0) +'**],'+ ISNULL(LTRIM(RTRIM(CAST(VALOR AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CLASSIFICDOC AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +'''
     '+ ')', 'LOGECFESTORNOS' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'LOGECFESTORNOS_U' AND type = 'TR')
   drop trigger LOGECFESTORNOS_U
go
create trigger dbo.LOGECFESTORNOS_U on dbo.LOGECFESTORNOS for update as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )    SELECT getdate(), null,'UPDATE LOGECFESTORNOS SET     RFILIAL = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(RFILIAL AS CHAR(254)))),0) +'**],    ROIDREFERENCIA = '+ ISNULL(LTRIM(RTRIM(CAST(ROIDREFERENCIA AS CHAR(254)))),0) +',    DATA = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DATA,20)))+''',120)','NULL')+',    RCAIXA = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(RCAIXA AS CHAR(254)))),0) +'**],    TIPODOC = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(TIPODOC AS CHAR(254)))),0) +'**],    VALOR = '+ ISNULL(LTRIM(RTRIM(CAST(VALOR AS CHAR(254)))),0) +',    CLASSIFICDOC = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CLASSIFICDOC AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''''+  ' WHERE     OID = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(OID AS CHAR(254)))),0) +'**]'  , 'LOGECFESTORNOS' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'LOGOPERADORCAIXA_D' AND type = 'TR')
  drop trigger LOGOPERADORCAIXA_D
go
create trigger dbo.LOGOPERADORCAIXA_D on dbo.LOGOPERADORCAIXA for delete as
    Begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
            SELECT getdate(), null,'DELETE FROM LOGOPERADORCAIXA WHERE 
ITEM = '+ RTRIM(LTRIM(CAST(ITEM as char(120)))) + ' ','LOGOPERADORCAIXA' from deleted
    End
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'LOGOPERADORCAIXA_I' AND type = 'TR')
   drop trigger LOGOPERADORCAIXA_I
go
create trigger dbo.LOGOPERADORCAIXA_I on dbo.LOGOPERADORCAIXA for insert as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
    SELECT getdate(), null,'INSERT INTO LOGOPERADORCAIXA(
        ITEM,    DATA,    CODOPENT,    CODOPSAI,    CODGERENTE,    CAIXA,    MODULO)
    VALUES (
    '+ ISNULL(LTRIM(RTRIM(CAST(ITEM AS CHAR(254)))),0) +','+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DATA,20 ))) +''',120)','NULL')+','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODOPENT AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODOPSAI AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODGERENTE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',  [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(CAIXA AS CHAR(254)))),0) +'**],'''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(MODULO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +'''
     '+ ')', 'LOGOPERADORCAIXA' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'LOGOPERADORCAIXA_U' AND type = 'TR')
   drop trigger LOGOPERADORCAIXA_U
go
create trigger dbo.LOGOPERADORCAIXA_U on dbo.LOGOPERADORCAIXA for update as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )    SELECT getdate(), null,'UPDATE LOGOPERADORCAIXA SET     DATA = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DATA,20)))+''',120)','NULL')+',    CODOPENT = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODOPENT AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CODOPSAI = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODOPSAI AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CODGERENTE = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODGERENTE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CAIXA = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(CAIXA AS CHAR(254)))),0) +'**],    MODULO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(MODULO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''''+  ' WHERE ITEM = '+ RTRIM(CAST(ITEM as char(254))) +  ''   , 'LOGOPERADORCAIXA' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'LOTE_D' AND type = 'TR')
  drop trigger LOTE_D
go
create trigger dbo.LOTE_D on dbo.LOTE for delete as
    Begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
            SELECT getdate(), null,'DELETE FROM LOTE WHERE 
Filial = '''+ RTRIM(LTRIM(Filial)) + '''  and CodPro = '''+ RTRIM(LTRIM(CodPro)) + '''  and LoteInterno = '''+ RTRIM(LTRIM(LoteInterno)) + ''' ','LOTE' from deleted
    End
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'LOTE_I' AND type = 'TR')
   drop trigger LOTE_I
go
create trigger dbo.LOTE_I on dbo.LOTE for insert as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
    SELECT getdate(), null,'INSERT INTO LOTE(
        FILIAL,    NUMORD,    CODPRO,    LOTEINTERNO,    LOTE,    QUANTIDADE,    DATALOTE,    VALIDADE,    LOTENF,    SITUACAO,    OBSERVACAO,    USUARIO,    DATA,    QTDEETIQIMPRESSA,    QTDENTRADACONFERIDA,    BITOLA,    TONALIDADE,    VENDEAPENASSALDO,    FILIALIMPORTADORA)
    VALUES (
    '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(FILIAL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(NUMORD AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODPRO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LOTEINTERNO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LOTE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(QUANTIDADE AS CHAR(254)))),0) +','+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DATALOTE,20 ))) +''',120)','NULL')+','+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,VALIDADE,20 ))) +''',120)','NULL')+','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LOTENF AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(SITUACAO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(OBSERVACAO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',  [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(USUARIO AS CHAR(254)))),0) +'**],'+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DATA,20 ))) +''',120)','NULL')+','+ ISNULL(LTRIM(RTRIM(CAST(QTDEETIQIMPRESSA AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(QTDENTRADACONFERIDA AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(BITOLA AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(TONALIDADE AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VENDEAPENASSALDO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(FILIALIMPORTADORA AS CHAR(254)))),0) +'
     '+ ')', 'LOTE' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'LOTE_U' AND type = 'TR')
   drop trigger LOTE_U
go
create trigger dbo.LOTE_U on dbo.LOTE for update as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )    SELECT getdate(), null,'UPDATE LOTE SET     NUMORD = '+ ISNULL(LTRIM(RTRIM(CAST(NUMORD AS CHAR(254)))),0) +',    LOTE = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LOTE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    QUANTIDADE = '+ ISNULL(LTRIM(RTRIM(CAST(QUANTIDADE AS CHAR(254)))),0) +',    DATALOTE = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DATALOTE,20)))+''',120)','NULL')+',    VALIDADE = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,VALIDADE,20)))+''',120)','NULL')+',    LOTENF = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LOTENF AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    SITUACAO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(SITUACAO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    OBSERVACAO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(OBSERVACAO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    USUARIO = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(USUARIO AS CHAR(254)))),0) +'**],    DATA = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DATA,20)))+''',120)','NULL')+',    QTDEETIQIMPRESSA = '+ ISNULL(LTRIM(RTRIM(CAST(QTDEETIQIMPRESSA AS CHAR(254)))),0) +',    QTDENTRADACONFERIDA = '+ ISNULL(LTRIM(RTRIM(CAST(QTDENTRADACONFERIDA AS CHAR(254)))),0) +',    BITOLA = '+ ISNULL(LTRIM(RTRIM(CAST(BITOLA AS CHAR(254)))),0) +',    TONALIDADE = '+ ISNULL(LTRIM(RTRIM(CAST(TONALIDADE AS CHAR(254)))),0) +',    VENDEAPENASSALDO = '+ ISNULL(LTRIM(RTRIM(CAST(VENDEAPENASSALDO AS CHAR(254)))),0) +',    FILIALIMPORTADORA = '+ ISNULL(LTRIM(RTRIM(CAST(FILIALIMPORTADORA AS CHAR(254)))),0) +''+  ' WHERE Filial = '''+ RTRIM(Filial)  + ''' and CodPro = '''+ RTRIM(CodPro)  + ''' and LoteInterno = '''+ RTRIM(LoteInterno)  + ''''   , 'LOTE' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'LOTEDERECEBIMENTOS_D' AND type = 'TR')
  drop trigger LOTEDERECEBIMENTOS_D
go
create trigger dbo.LOTEDERECEBIMENTOS_D on dbo.LOTEDERECEBIMENTOS for delete as
    Begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
            SELECT getdate(), null,'DELETE FROM LOTEDERECEBIMENTOS WHERE 
RITEM = '+ RTRIM(LTRIM(CAST(RITEM as char(120)))) + ' ','LOTEDERECEBIMENTOS' from deleted
    End
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'LOTEDERECEBIMENTOS_I' AND type = 'TR')
   drop trigger LOTEDERECEBIMENTOS_I
go
create trigger dbo.LOTEDERECEBIMENTOS_I on dbo.LOTEDERECEBIMENTOS for insert as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
    SELECT getdate(), null,'INSERT INTO LOTEDERECEBIMENTOS(
        DATAREMESSA,    RITEM,    LOTEDEPOSITO,    DATADEPOSITO,    LOTEREMESSA)
    VALUES (
    '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DATAREMESSA,20 ))) +''',120)','NULL')+','+ ISNULL(LTRIM(RTRIM(CAST(RITEM AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(LOTEDEPOSITO AS CHAR(254)))),0) +','+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DATADEPOSITO,20 ))) +''',120)','NULL')+','+ ISNULL(LTRIM(RTRIM(CAST(LOTEREMESSA AS CHAR(254)))),0) +'
     '+ ')', 'LOTEDERECEBIMENTOS' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'LOTEDERECEBIMENTOS_U' AND type = 'TR')
   drop trigger LOTEDERECEBIMENTOS_U
go
create trigger dbo.LOTEDERECEBIMENTOS_U on dbo.LOTEDERECEBIMENTOS for update as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )    SELECT getdate(), null,'UPDATE LOTEDERECEBIMENTOS SET     DATAREMESSA = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DATAREMESSA,20)))+''',120)','NULL')+',    LOTEDEPOSITO = '+ ISNULL(LTRIM(RTRIM(CAST(LOTEDEPOSITO AS CHAR(254)))),0) +',    DATADEPOSITO = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DATADEPOSITO,20)))+''',120)','NULL')+',    LOTEREMESSA = '+ ISNULL(LTRIM(RTRIM(CAST(LOTEREMESSA AS CHAR(254)))),0) +''+  ' WHERE RITEM = '+ RTRIM(CAST(RITEM as char(254))) +  ''   , 'LOTEDERECEBIMENTOS' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'LOTEMONTAGEM_D' AND type = 'TR')
  drop trigger LOTEMONTAGEM_D
go
create trigger dbo.LOTEMONTAGEM_D on dbo.LOTEMONTAGEM for delete as
    Begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
            SELECT getdate(), null,'DELETE FROM LOTEMONTAGEM WHERE 
filial = '''+ RTRIM(LTRIM(filial)) + '''  and numPed = '+ RTRIM(LTRIM(CAST(numPed as char(120)))) + ' ','LOTEMONTAGEM' from deleted
    End
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'LOTEMONTAGEM_I' AND type = 'TR')
   drop trigger LOTEMONTAGEM_I
go
create trigger dbo.LOTEMONTAGEM_I on dbo.LOTEMONTAGEM for insert as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
    SELECT getdate(), null,'INSERT INTO LOTEMONTAGEM(
        FILIAL,    NUMPED,    LOTE,    DATA,    USUARIO,    VIAREQ)
    VALUES (
    '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(FILIAL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(NUMPED AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(LOTE AS CHAR(254)))),0) +','+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DATA,20 ))) +''',120)','NULL')+',  [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(USUARIO AS CHAR(254)))),0) +'**],'+ ISNULL(LTRIM(RTRIM(CAST(VIAREQ AS CHAR(254)))),0) +'
     '+ ')', 'LOTEMONTAGEM' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'LOTEMONTAGEM_U' AND type = 'TR')
   drop trigger LOTEMONTAGEM_U
go
create trigger dbo.LOTEMONTAGEM_U on dbo.LOTEMONTAGEM for update as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )    SELECT getdate(), null,'UPDATE LOTEMONTAGEM SET     LOTE = '+ ISNULL(LTRIM(RTRIM(CAST(LOTE AS CHAR(254)))),0) +',    DATA = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DATA,20)))+''',120)','NULL')+',    USUARIO = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(USUARIO AS CHAR(254)))),0) +'**],    VIAREQ = '+ ISNULL(LTRIM(RTRIM(CAST(VIAREQ AS CHAR(254)))),0) +''+  ' WHERE filial = '''+ RTRIM(filial)  + ''' and numPed = '+ RTRIM(CAST(numPed as char(254))) +  ''   , 'LOTEMONTAGEM' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'MEIOSPAGAMENTOECF_D' AND type = 'TR')
  drop trigger MEIOSPAGAMENTOECF_D
go
create trigger dbo.MEIOSPAGAMENTOECF_D on dbo.MEIOSPAGAMENTOECF for delete as
    Begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
            SELECT getdate(), null,'DELETE FROM MEIOSPAGAMENTOECF WHERE 
OID = '+ RTRIM(LTRIM(CAST(OID as char(120)))) + ' ','MEIOSPAGAMENTOECF' from deleted
    End
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'MEIOSPAGAMENTOECF_I' AND type = 'TR')
   drop trigger MEIOSPAGAMENTOECF_I
go
create trigger dbo.MEIOSPAGAMENTOECF_I on dbo.MEIOSPAGAMENTOECF for insert as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
    SELECT getdate(), null,'INSERT INTO MEIOSPAGAMENTOECF(
        SERIALIMPRESSORA,    COO,    CONTOP,    RTIPODEDOCUMENTO,    TIPOCUPOM,    DATA,    VALOR,    GNF,    OIDSERIALECF)
    VALUES (
    '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(SERIALIMPRESSORA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(COO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CONTOP AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(RTIPODEDOCUMENTO AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(TIPOCUPOM AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DATA,20 ))) +''',120)','NULL')+','+ ISNULL(LTRIM(RTRIM(CAST(VALOR AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(GNF AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(OIDSERIALECF AS CHAR(254)))),0) +')
     ', 'MEIOSPAGAMENTOECF' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'MEIOSPAGAMENTOECF_U' AND type = 'TR')
   drop trigger MEIOSPAGAMENTOECF_U
go
create trigger dbo.MEIOSPAGAMENTOECF_U on dbo.MEIOSPAGAMENTOECF for update as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )    SELECT getdate(), null,'UPDATE MEIOSPAGAMENTOECF SET     SERIALIMPRESSORA = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(SERIALIMPRESSORA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    COO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(COO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CONTOP = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CONTOP AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    RTIPODEDOCUMENTO = '+ ISNULL(LTRIM(RTRIM(CAST(RTIPODEDOCUMENTO AS CHAR(254)))),0) +',    TIPOCUPOM = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(TIPOCUPOM AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    DATA = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DATA,20)))+''',120)','NULL')+',    VALOR = '+ ISNULL(LTRIM(RTRIM(CAST(VALOR AS CHAR(254)))),0) +',    GNF = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(GNF AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    OIDSERIALECF = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(OIDSERIALECF AS CHAR(254)))),0) +'**]'+  ' WHERE     OID = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(OID AS CHAR(254)))),0) +'**]'  , 'MEIOSPAGAMENTOECF' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'MOVFCXACAD_D' AND type = 'TR')
  drop trigger MOVFCXACAD_D
go
create trigger dbo.MOVFCXACAD_D on dbo.MOVFCXACAD for delete as
    Begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
            SELECT getdate(), null,'DELETE FROM MOVFCXACAD WHERE 
caixa = '+ RTRIM(LTRIM(CAST(caixa as char(120)))) + '  and     DATAFCXA = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DATAFCXA,20)))+''',120)','NULL') +' and filial = '''+ RTRIM(LTRIM(filial)) + ''' ','MOVFCXACAD' from deleted
    End
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'MOVFCXACAD_I' AND type = 'TR')
   drop trigger MOVFCXACAD_I
go
create trigger dbo.MOVFCXACAD_I on dbo.MOVFCXACAD for insert as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
    SELECT getdate(), null,'INSERT INTO MOVFCXACAD(
        CAIXA,    DATAFCXA,    TOTALVISTA,    TOTALPRAZO,    VALORFRETE,    VALORDIFER,    TOTALFCXA,    CTBFRETE,    CTBDIFERENCA,    INTEGRADO,    FILIAL,    RDOCDEORIGEM,    VALRECENT,    USUARIO,    VALFRETEVISTA,    VALFRETEPRAZO)
    VALUES (
      [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(CAIXA AS CHAR(254)))),0) +'**],'+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DATAFCXA,20 ))) +''',120)','NULL')+','+ ISNULL(LTRIM(RTRIM(CAST(TOTALVISTA AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(TOTALPRAZO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALORFRETE AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALORDIFER AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(TOTALFCXA AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CTBFRETE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CTBDIFERENCA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(INTEGRADO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(FILIAL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',  [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(RDOCDEORIGEM AS CHAR(254)))),0) +'**],'+ ISNULL(LTRIM(RTRIM(CAST(VALRECENT AS CHAR(254)))),0) +',  [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(USUARIO AS CHAR(254)))),0) +'**],'+ ISNULL(LTRIM(RTRIM(CAST(VALFRETEVISTA AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALFRETEPRAZO AS CHAR(254)))),0) +'
     '+ ')', 'MOVFCXACAD' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'MOVFCXACAD_U' AND type = 'TR')
   drop trigger MOVFCXACAD_U
go
create trigger dbo.MOVFCXACAD_U on dbo.MOVFCXACAD for update as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )    SELECT getdate(), null,'UPDATE MOVFCXACAD SET     TOTALVISTA = '+ ISNULL(LTRIM(RTRIM(CAST(TOTALVISTA AS CHAR(254)))),0) +',    TOTALPRAZO = '+ ISNULL(LTRIM(RTRIM(CAST(TOTALPRAZO AS CHAR(254)))),0) +',    VALORFRETE = '+ ISNULL(LTRIM(RTRIM(CAST(VALORFRETE AS CHAR(254)))),0) +',    VALORDIFER = '+ ISNULL(LTRIM(RTRIM(CAST(VALORDIFER AS CHAR(254)))),0) +',    TOTALFCXA = '+ ISNULL(LTRIM(RTRIM(CAST(TOTALFCXA AS CHAR(254)))),0) +',    CTBFRETE = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CTBFRETE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CTBDIFERENCA = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CTBDIFERENCA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    INTEGRADO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(INTEGRADO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    RDOCDEORIGEM = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(RDOCDEORIGEM AS CHAR(254)))),0) +'**],    VALRECENT = '+ ISNULL(LTRIM(RTRIM(CAST(VALRECENT AS CHAR(254)))),0) +',    USUARIO = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(USUARIO AS CHAR(254)))),0) +'**],    VALFRETEVISTA = '+ ISNULL(LTRIM(RTRIM(CAST(VALFRETEVISTA AS CHAR(254)))),0) +',    VALFRETEPRAZO = '+ ISNULL(LTRIM(RTRIM(CAST(VALFRETEPRAZO AS CHAR(254)))),0) +''+  ' WHERE     caixa = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(caixa AS CHAR(254)))),0) +'**] and     DATAFCXA = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DATAFCXA,20)))+''',120)','NULL')+' and filial = '''+ RTRIM(filial)  + ''''   , 'MOVFCXACAD' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'NFENTRACAD_D' AND type = 'TR')
  drop trigger NFENTRACAD_D
go
create trigger dbo.NFENTRACAD_D on dbo.NFENTRACAD for delete as
    Begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
            SELECT getdate(), null,'DELETE FROM NFENTRACAD WHERE 
numord = '+ RTRIM(LTRIM(CAST(numord as char(120)))) + ' ','NFENTRACAD' from deleted
    End
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'NFENTRACAD_I' AND type = 'TR')
   drop trigger NFENTRACAD_I
go
create trigger dbo.NFENTRACAD_I on dbo.NFENTRACAD for insert as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
    SELECT getdate(), null,'INSERT INTO NFENTRACAD(
        NUMNOTA,    SERIE,    CODFOR,    DTEMIS,    DTCHEG,    ESPDOC,    FILIAL,    ESTADO,    CFO,    TPO,    VALCONTAB,    BASEICM,    BASEICM2,    BASEICM3,    ALQICM,    ALQICM2,    ALQICM3,    VALICM,    VALICM2,    VALICM3,    BASEIPI,    VALIPI,    VALSEMIPI,    VALSEMICM,    DESTAQIPI,    BASESTRIB,    VALSUBSTRI,    OBS,    BASEISS,    VALISS,    VALFRETE,    DESPINCL,    OUTRICM,    OUTRIPI,    DESPNINCL,    CCUSTO,    CODREP,    NUMPED,    VALENTRAD,    DESCONTO,    NUMORD,    ATUALIZ,    FLAGATUA,    IPIFRETE,    FILTRANSF,    TIPONF,    FLAGCONTAB,    CUSPARGER,    ICMSDESPNI,    CPAG,    CXA,    FLU,    CTB,    CUS,    INTEGRADO,    TIPCOMPRA,    MODELONF,    EST,    LIF,    CMED,    STATUS,    LIBERADO,    DTSTAT,    CODMOE,    VALMOE,    NFORDCOMP,    LOCALPORTA,    CONTA,    CODMETRA,    CODTRAN,    CODNATOP,    VALIRRF,    IRRF,    DTCANCEL,    VALNFCHE,    NUMORDFIS,    IMPOGER,    VALCICM4,    BASEICM4,    ALQICM4,    VALICM4,    CUSTVEN,    ICMSFONTE,    CODVEND,    VRIPI,    BASEICM5,    ALQICM5,    VALICM5,    OIDDOCDEORIGEM,    CODMOTDEV,    CODREEM,    ATUACUM,    JACOMIS,    COMISSAO,    EXCED,    CONTABILIZADO,    CONFCODIGO,    ICMSIPI,    CODCLIOUT,    DEPDESTINO,    TPOOUTRASAI,    SITSAGA,    HISTORICO,    VALIDADE,    SITPRODUTO,    FRETESUBSTRIBUTARIA,    SITLOTE,    CALCULARJUROSRENTABILIDADE,    ORDEMDECOMPRA,    AVALIACAOREC,    BO,    EXPORTADO,    NUMORDANT,    GUIATRAFEGO,    SITUACAODEVOLUCAO,    DESPESASIMPORTACAO,    IDREC)
    VALUES (
    '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NUMNOTA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(SERIE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',  [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(CODFOR AS CHAR(254)))),0) +'**],'+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DTEMIS,20 ))) +''',120)','NULL')+','+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DTCHEG,20 ))) +''',120)','NULL')+','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ESPDOC AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(FILIAL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ESTADO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CFO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(TPO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(VALCONTAB AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(BASEICM AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(BASEICM2 AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(BASEICM3 AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ALQICM AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ALQICM2 AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ALQICM3 AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALICM AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALICM2 AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALICM3 AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(BASEIPI AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALIPI AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALSEMIPI AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALSEMICM AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(DESTAQIPI AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(BASESTRIB AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALSUBSTRI AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(OBS AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(BASEISS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALISS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALFRETE AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(DESPINCL AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(OUTRICM AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(OUTRIPI AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(DESPNINCL AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CCUSTO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODREP AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(NUMPED AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALENTRAD AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(DESCONTO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(NUMORD AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ATUALIZ AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(FLAGATUA AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(IPIFRETE AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(FILTRANSF AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(TIPONF AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(FLAGCONTAB AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(CUSPARGER AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ICMSDESPNI AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(CPAG AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(CXA AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(FLU AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(CTB AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CUS AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(INTEGRADO AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(TIPCOMPRA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(MODELONF AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(EST AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(LIF AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(CMED AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(STATUS AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(LIBERADO AS CHAR(254)))),0) +','+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DTSTAT,20 ))) +''',120)','NULL')+','+ ISNULL(LTRIM(RTRIM(CAST(CODMOE AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALMOE AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NFORDCOMP AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',  [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(LOCALPORTA AS CHAR(254)))),0) +'**],  [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(CONTA AS CHAR(254)))),0) +'**],'''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODMETRA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODTRAN AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',  [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(CODNATOP AS CHAR(254)))),0) +'**],'+ ISNULL(LTRIM(RTRIM(CAST(VALIRRF AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(IRRF AS CHAR(254)))),0) +','+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DTCANCEL,20 ))) +''',120)','NULL')+','+ ISNULL(LTRIM(RTRIM(CAST(VALNFCHE AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(NUMORDFIS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(IMPOGER AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALCICM4 AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(BASEICM4 AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ALQICM4 AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALICM4 AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(CUSTVEN AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ICMSFONTE AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODVEND AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(VRIPI AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(BASEICM5 AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ALQICM5 AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALICM5 AS CHAR(254)))),0) +',  [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(OIDDOCDEORIGEM AS CHAR(254)))),0) +'**],'''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODMOTDEV AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODREEM AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(ATUACUM AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(JACOMIS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(COMISSAO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(EXCED AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(CONTABILIZADO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(CONFCODIGO AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ICMSIPI AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(CODCLIOUT AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(DEPDESTINO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(TPOOUTRASAI AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(SITSAGA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(HISTORICO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(VALIDADE AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(SITPRODUTO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(FRETESUBSTRIBUTARIA AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(SITLOTE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(CALCULARJUROSRENTABILIDADE AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ORDEMDECOMPRA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(AVALIACAOREC AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(BO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(EXPORTADO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(NUMORDANT AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(GUIATRAFEGO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(SITUACAODEVOLUCAO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(DESPESASIMPORTACAO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(IDREC AS CHAR(254)))),0) +'
     '+ ')', 'NFENTRACAD' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'NFENTRACAD_U' AND type = 'TR')
   drop trigger NFENTRACAD_U
go
create trigger dbo.NFENTRACAD_U on dbo.NFENTRACAD for update as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )    SELECT getdate(), null,'UPDATE NFENTRACAD SET     NUMNOTA = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NUMNOTA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    SERIE = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(SERIE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CODFOR = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(CODFOR AS CHAR(254)))),0) +'**],    DTEMIS = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DTEMIS,20)))+''',120)','NULL')+',    DTCHEG = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DTCHEG,20)))+''',120)','NULL')+',    ESPDOC = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ESPDOC AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    FILIAL = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(FILIAL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    ESTADO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ESTADO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CFO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CFO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    TPO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(TPO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    VALCONTAB = '+ ISNULL(LTRIM(RTRIM(CAST(VALCONTAB AS CHAR(254)))),0) +',    BASEICM = '+ ISNULL(LTRIM(RTRIM(CAST(BASEICM AS CHAR(254)))),0) +',    BASEICM2 = '+ ISNULL(LTRIM(RTRIM(CAST(BASEICM2 AS CHAR(254)))),0) +',    BASEICM3 = '+ ISNULL(LTRIM(RTRIM(CAST(BASEICM3 AS CHAR(254)))),0) +',    ALQICM = '+ ISNULL(LTRIM(RTRIM(CAST(ALQICM AS CHAR(254)))),0) +',    ALQICM2 = '+ ISNULL(LTRIM(RTRIM(CAST(ALQICM2 AS CHAR(254)))),0) +',    ALQICM3 = '+ ISNULL(LTRIM(RTRIM(CAST(ALQICM3 AS CHAR(254)))),0) +',    VALICM = '+ ISNULL(LTRIM(RTRIM(CAST(VALICM AS CHAR(254)))),0) +',    VALICM2 = '+ ISNULL(LTRIM(RTRIM(CAST(VALICM2 AS CHAR(254)))),0) +',    VALICM3 = '+ ISNULL(LTRIM(RTRIM(CAST(VALICM3 AS CHAR(254)))),0) +',    BASEIPI = '+ ISNULL(LTRIM(RTRIM(CAST(BASEIPI AS CHAR(254)))),0) +',    VALIPI = '+ ISNULL(LTRIM(RTRIM(CAST(VALIPI AS CHAR(254)))),0) +',    VALSEMIPI = '+ ISNULL(LTRIM(RTRIM(CAST(VALSEMIPI AS CHAR(254)))),0) +',    VALSEMICM = '+ ISNULL(LTRIM(RTRIM(CAST(VALSEMICM AS CHAR(254)))),0) +',    DESTAQIPI = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(DESTAQIPI AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    BASESTRIB = '+ ISNULL(LTRIM(RTRIM(CAST(BASESTRIB AS CHAR(254)))),0) +',    VALSUBSTRI = '+ ISNULL(LTRIM(RTRIM(CAST(VALSUBSTRI AS CHAR(254)))),0) +',    OBS = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(OBS AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    BASEISS = '+ ISNULL(LTRIM(RTRIM(CAST(BASEISS AS CHAR(254)))),0) +',    VALISS = '+ ISNULL(LTRIM(RTRIM(CAST(VALISS AS CHAR(254)))),0) +',    VALFRETE = '+ ISNULL(LTRIM(RTRIM(CAST(VALFRETE AS CHAR(254)))),0) +',    DESPINCL = '+ ISNULL(LTRIM(RTRIM(CAST(DESPINCL AS CHAR(254)))),0) +',    OUTRICM = '+ ISNULL(LTRIM(RTRIM(CAST(OUTRICM AS CHAR(254)))),0) +',    OUTRIPI = '+ ISNULL(LTRIM(RTRIM(CAST(OUTRIPI AS CHAR(254)))),0) +',    DESPNINCL = '+ ISNULL(LTRIM(RTRIM(CAST(DESPNINCL AS CHAR(254)))),0) +',    CCUSTO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CCUSTO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CODREP = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODREP AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    NUMPED = '+ ISNULL(LTRIM(RTRIM(CAST(NUMPED AS CHAR(254)))),0) +',    VALENTRAD = '+ ISNULL(LTRIM(RTRIM(CAST(VALENTRAD AS CHAR(254)))),0) +',    DESCONTO = '+ ISNULL(LTRIM(RTRIM(CAST(DESCONTO AS CHAR(254)))),0) +',    ATUALIZ = '+ ISNULL(LTRIM(RTRIM(CAST(ATUALIZ AS CHAR(254)))),0) +',    FLAGATUA = '+ ISNULL(LTRIM(RTRIM(CAST(FLAGATUA AS CHAR(254)))),0) +',    IPIFRETE = '+ ISNULL(LTRIM(RTRIM(CAST(IPIFRETE AS CHAR(254)))),0) +',    FILTRANSF = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(FILTRANSF AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    TIPONF = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(TIPONF AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    FLAGCONTAB = '+ ISNULL(LTRIM(RTRIM(CAST(FLAGCONTAB AS CHAR(254)))),0) +',    CUSPARGER = '+ ISNULL(LTRIM(RTRIM(CAST(CUSPARGER AS CHAR(254)))),0) +',    ICMSDESPNI = '+ ISNULL(LTRIM(RTRIM(CAST(ICMSDESPNI AS CHAR(254)))),0) +',    CPAG = '+ ISNULL(LTRIM(RTRIM(CAST(CPAG AS CHAR(254)))),0) +',    CXA = '+ ISNULL(LTRIM(RTRIM(CAST(CXA AS CHAR(254)))),0) +',    FLU = '+ ISNULL(LTRIM(RTRIM(CAST(FLU AS CHAR(254)))),0) +',    CTB = '+ ISNULL(LTRIM(RTRIM(CAST(CTB AS CHAR(254)))),0) +',    CUS = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CUS AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    INTEGRADO = '+ ISNULL(LTRIM(RTRIM(CAST(INTEGRADO AS CHAR(254)))),0) +',    TIPCOMPRA = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(TIPCOMPRA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    MODELONF = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(MODELONF AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    EST = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(EST AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    LIF = '+ ISNULL(LTRIM(RTRIM(CAST(LIF AS CHAR(254)))),0) +',    CMED = '+ ISNULL(LTRIM(RTRIM(CAST(CMED AS CHAR(254)))),0) +',    STATUS = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(STATUS AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    LIBERADO = '+ ISNULL(LTRIM(RTRIM(CAST(LIBERADO AS CHAR(254)))),0) +',    DTSTAT = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DTSTAT,20)))+''',120)','NULL')+',    CODMOE = '+ ISNULL(LTRIM(RTRIM(CAST(CODMOE AS CHAR(254)))),0) +',    VALMOE = '+ ISNULL(LTRIM(RTRIM(CAST(VALMOE AS CHAR(254)))),0) +',    NFORDCOMP = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NFORDCOMP AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    LOCALPORTA = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(LOCALPORTA AS CHAR(254)))),0) +'**],    CONTA = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(CONTA AS CHAR(254)))),0) +'**],    CODMETRA = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODMETRA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CODTRAN = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODTRAN AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CODNATOP = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(CODNATOP AS CHAR(254)))),0) +'**],    VALIRRF = '+ ISNULL(LTRIM(RTRIM(CAST(VALIRRF AS CHAR(254)))),0) +',    IRRF = '+ ISNULL(LTRIM(RTRIM(CAST(IRRF AS CHAR(254)))),0) +',    DTCANCEL = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DTCANCEL,20)))+''',120)','NULL')+',    VALNFCHE = '+ ISNULL(LTRIM(RTRIM(CAST(VALNFCHE AS CHAR(254)))),0) +',    NUMORDFIS = '+ ISNULL(LTRIM(RTRIM(CAST(NUMORDFIS AS CHAR(254)))),0) +',    IMPOGER = '+ ISNULL(LTRIM(RTRIM(CAST(IMPOGER AS CHAR(254)))),0) +',    VALCICM4 = '+ ISNULL(LTRIM(RTRIM(CAST(VALCICM4 AS CHAR(254)))),0) +',    BASEICM4 = '+ ISNULL(LTRIM(RTRIM(CAST(BASEICM4 AS CHAR(254)))),0) +',    ALQICM4 = '+ ISNULL(LTRIM(RTRIM(CAST(ALQICM4 AS CHAR(254)))),0) +',    VALICM4 = '+ ISNULL(LTRIM(RTRIM(CAST(VALICM4 AS CHAR(254)))),0) +',    CUSTVEN = '+ ISNULL(LTRIM(RTRIM(CAST(CUSTVEN AS CHAR(254)))),0) +',    ICMSFONTE = '+ ISNULL(LTRIM(RTRIM(CAST(ICMSFONTE AS CHAR(254)))),0) +',    CODVEND = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODVEND AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    VRIPI = '+ ISNULL(LTRIM(RTRIM(CAST(VRIPI AS CHAR(254)))),0) +',    BASEICM5 = '+ ISNULL(LTRIM(RTRIM(CAST(BASEICM5 AS CHAR(254)))),0) +',    ALQICM5 = '+ ISNULL(LTRIM(RTRIM(CAST(ALQICM5 AS CHAR(254)))),0) +',    VALICM5 = '+ ISNULL(LTRIM(RTRIM(CAST(VALICM5 AS CHAR(254)))),0) +',    OIDDOCDEORIGEM = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(OIDDOCDEORIGEM AS CHAR(254)))),0) +'**],    CODMOTDEV = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODMOTDEV AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CODREEM = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODREEM AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    ATUACUM = '+ ISNULL(LTRIM(RTRIM(CAST(ATUACUM AS CHAR(254)))),0) +',    JACOMIS = '+ ISNULL(LTRIM(RTRIM(CAST(JACOMIS AS CHAR(254)))),0) +',    COMISSAO = '+ ISNULL(LTRIM(RTRIM(CAST(COMISSAO AS CHAR(254)))),0) +',    EXCED = '+ ISNULL(LTRIM(RTRIM(CAST(EXCED AS CHAR(254)))),0) +',    CONTABILIZADO = '+ ISNULL(LTRIM(RTRIM(CAST(CONTABILIZADO AS CHAR(254)))),0) +',    CONFCODIGO = '+ ISNULL(LTRIM(RTRIM(CAST(CONFCODIGO AS CHAR(254)))),0) +',    ICMSIPI = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ICMSIPI AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CODCLIOUT = '+ ISNULL(LTRIM(RTRIM(CAST(CODCLIOUT AS CHAR(254)))),0) +',    DEPDESTINO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(DEPDESTINO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    TPOOUTRASAI = '+ ISNULL(LTRIM(RTRIM(CAST(TPOOUTRASAI AS CHAR(254)))),0) +',    SITSAGA = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(SITSAGA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    HISTORICO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(HISTORICO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    VALIDADE = '+ ISNULL(LTRIM(RTRIM(CAST(VALIDADE AS CHAR(254)))),0) +',    SITPRODUTO = '+ ISNULL(LTRIM(RTRIM(CAST(SITPRODUTO AS CHAR(254)))),0) +',    FRETESUBSTRIBUTARIA = '+ ISNULL(LTRIM(RTRIM(CAST(FRETESUBSTRIBUTARIA AS CHAR(254)))),0) +',    SITLOTE = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(SITLOTE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CALCULARJUROSRENTABILIDADE = '+ ISNULL(LTRIM(RTRIM(CAST(CALCULARJUROSRENTABILIDADE AS CHAR(254)))),0) +',    ORDEMDECOMPRA = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ORDEMDECOMPRA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    AVALIACAOREC = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(AVALIACAOREC AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    BO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(BO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    EXPORTADO = '+ ISNULL(LTRIM(RTRIM(CAST(EXPORTADO AS CHAR(254)))),0) +',    NUMORDANT = '+ ISNULL(LTRIM(RTRIM(CAST(NUMORDANT AS CHAR(254)))),0) +',    GUIATRAFEGO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(GUIATRAFEGO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    SITUACAODEVOLUCAO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(SITUACAODEVOLUCAO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    DESPESASIMPORTACAO = '+ ISNULL(LTRIM(RTRIM(CAST(DESPESASIMPORTACAO AS CHAR(254)))),0) +',    IDREC = '+ ISNULL(LTRIM(RTRIM(CAST(IDREC AS CHAR(254)))),0) +''+  ' WHERE numord = '+ RTRIM(CAST(numord as char(254))) +  ''   , 'NFENTRACAD' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'NFSAIDACAD_D' AND type = 'TR')
  drop trigger NFSAIDACAD_D
go
create trigger dbo.NFSAIDACAD_D on dbo.NFSAIDACAD for delete as
    Begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
            SELECT getdate(), null,'DELETE FROM NFSAIDACAD WHERE 
numord = '+ RTRIM(LTRIM(CAST(numord as char(120)))) + ' ','NFSAIDACAD' from deleted
    End
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'NFSAIDACAD_I' AND type = 'TR')
   drop trigger NFSAIDACAD_I
go
create trigger dbo.NFSAIDACAD_I on dbo.NFSAIDACAD for insert as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
    SELECT getdate(), null,'INSERT INTO NFSAIDACAD(
        BASEICM3,    ALQICM,    ALQICM2,    ALQICM3,    VALICM,    VALICM2,    VALICM3,    BASEIPI,    VALIPI,    VALSEMICM,    VALSEMIPI,    BASESTRIB,    VALSUBSTRI,    VALTRIBDIF,    DESTAQIPI,    VALSERVICO,    VALISS,    VALFRETE,    VALSEGURO,    FRETEINC,    OUTRICM,    OUTRIPI,    CCUSTO,    OBS,    CODVEND,    NUMPED,    VALENTRAD,    CODMETRA,    CODTRAN,    DESCONTO,    COMISSAO,    NUMORD,    FATURADO,    ATUALIZ,    FLAGEMIT,    FLAGREGFIS,    FLAGATUA,    ICMSIPI,    VALEMBA,    CODROTE,    CODNATOP,    FILTRANSF,    TIPONF,    FLAGINTER,    FLAGCONTAB,    CODSITEST,    CODSITFED,    PERCSUBST,    LUCRO,    REC,    CXA,    FLU,    CTB,    ATF,    CUS,    INTEGRADO,    DTCANCEL,    BASEISS,    MODELONF,    CONDPAG,    EST,    LIF,    FAT,    EXPORTADO,    CODMES,    PERIPI,    LOCALPORTA,    CONTA,    CODTRAN2,    NUMNOTA,    SERIE,    CODCLIE,    DTEMIS,    ESPDOC,    FILIAL,    ESTADO,    CFO,    TPO,    VALCONTAB,    BASEICM,    BASEICM2,    CUPOMINI,    CUPOMFIM,    GVE,    BASEICM4,    ALQICM4,    VALICM4,    CLASVEND,    FLAGCONS,    CLIFIM,    EXPORTA,    PEDIMPO,    TIPONOTA,    NUMECF,    NUMCUPON,    VALNFCHE,    CLIENTEA,    NORDVEN,    NUMNFECF,    BASEICM5,    ALQICM5,    VALICM5,    NUMORDFIS,    IMPOGER,    ICMSFONTE,    TOTMERC,    TOTPESO,    TXFINAN,    EXCED,    CODLIS,    OIDDOCDEORIGEM,    ATUACUM,    JACOMIS,    CONTABILIZADO,    CODFOROUT,    DEPORIGEM,    TPOOUTRAENT,    CONTREDZ,    GT,    BASEIR,    ALIQIR,    CODGER,    OIDREVENDA,    HISTORICO,    BASEINSS,    ALIQINSS,    VALINSS,    ALIQISSRET,    BASEISSRET,    VALISSRET,    VALIRRF,    NFFUTURA,    NORDEXPEDIC,    VALIDADE,    SITPRODUTO,    DESPNAOINCLUSAS,    ICMSDESPNAOINCLUSAS,    FRETESUBSTRIBUTARIA,    SERIEECF,    GTFIM,    VALCANECF,    VALDESCECF,    CONTREIOPE,    NUMORDECF,    OUTRASDESPESASINCLUSAS,    TIPOENTR,    TOTALVALORICMS,    TOTALPRECOCOMICMS,    DESPESASIMPORTACAO,    OIDSERIALECF)
    VALUES (
    '+ ISNULL(LTRIM(RTRIM(CAST(BASEICM3 AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ALQICM AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ALQICM2 AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ALQICM3 AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALICM AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALICM2 AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALICM3 AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(BASEIPI AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALIPI AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALSEMICM AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALSEMIPI AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(BASESTRIB AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALSUBSTRI AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALTRIBDIF AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(DESTAQIPI AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(VALSERVICO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALISS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALFRETE AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALSEGURO AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(FRETEINC AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(OUTRICM AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(OUTRIPI AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CCUSTO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(OBS AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODVEND AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(NUMPED AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALENTRAD AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODMETRA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODTRAN AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(DESCONTO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(COMISSAO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(NUMORD AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(FATURADO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ATUALIZ AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(FLAGEMIT AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(FLAGREGFIS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(FLAGATUA AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ICMSIPI AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(VALEMBA AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODROTE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',  [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(CODNATOP AS CHAR(254)))),0) +'**],'''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(FILTRANSF AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(TIPONF AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(FLAGINTER AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(FLAGCONTAB AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODSITEST AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODSITFED AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(PERCSUBST AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(LUCRO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(REC AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(CXA AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(FLU AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(CTB AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ATF AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CUS AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(INTEGRADO AS CHAR(254)))),0) +','+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DTCANCEL,20 ))) +''',120)','NULL')+','+ ISNULL(LTRIM(RTRIM(CAST(BASEISS AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(MODELONF AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',  [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(CONDPAG AS CHAR(254)))),0) +'**],'''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(EST AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(LIF AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(FAT AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(EXPORTADO AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODMES AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(PERIPI AS CHAR(254)))),0) +',  [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(LOCALPORTA AS CHAR(254)))),0) +'**],  [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(CONTA AS CHAR(254)))),0) +'**],'''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODTRAN2 AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NUMNOTA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(SERIE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',  [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(CODCLIE AS CHAR(254)))),0) +'**],'+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DTEMIS,20 ))) +''',120)','NULL')+','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ESPDOC AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(FILIAL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ESTADO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CFO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(TPO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(VALCONTAB AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(BASEICM AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(BASEICM2 AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CUPOMINI AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CUPOMFIM AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(GVE AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(BASEICM4 AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ALQICM4 AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALICM4 AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CLASVEND AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(FLAGCONS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(CLIFIM AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(EXPORTA AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(PEDIMPO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(TIPONOTA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NUMECF AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NUMCUPON AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(VALNFCHE AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(CLIENTEA AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(NORDVEN AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NUMNFECF AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(BASEICM5 AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ALQICM5 AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALICM5 AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(NUMORDFIS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(IMPOGER AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ICMSFONTE AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(TOTMERC AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(TOTPESO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(TXFINAN AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(EXCED AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODLIS AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',  [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(OIDDOCDEORIGEM AS CHAR(254)))),0) +'**],'+ ISNULL(LTRIM(RTRIM(CAST(ATUACUM AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(JACOMIS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(CONTABILIZADO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(CODFOROUT AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(DEPORIGEM AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(TPOOUTRAENT AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CONTREDZ AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(GT AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(BASEIR AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ALIQIR AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODGER AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',  [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(OIDREVENDA AS CHAR(254)))),0) +'**],'''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(HISTORICO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(BASEINSS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ALIQINSS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALINSS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ALIQISSRET AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(BASEISSRET AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALISSRET AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALIRRF AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(NFFUTURA AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(NORDEXPEDIC AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALIDADE AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(SITPRODUTO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(DESPNAOINCLUSAS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ICMSDESPNAOINCLUSAS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(FRETESUBSTRIBUTARIA AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(SERIEECF AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(GTFIM AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALCANECF AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALDESCECF AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CONTREIOPE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(NUMORDECF AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(OUTRASDESPESASINCLUSAS AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(TIPOENTR AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(TOTALVALORICMS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(TOTALPRECOCOMICMS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(DESPESASIMPORTACAO AS CHAR(254)))),0) +',  [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(OIDSERIALECF AS CHAR(254)))),0) +'**]
     '+ ')', 'NFSAIDACAD' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'NFSAIDACAD_U' AND type = 'TR')
   drop trigger NFSAIDACAD_U
go
create trigger dbo.NFSAIDACAD_U on dbo.NFSAIDACAD for update as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )    SELECT getdate(), null,'UPDATE NFSAIDACAD SET     BASEICM3 = '+ ISNULL(LTRIM(RTRIM(CAST(BASEICM3 AS CHAR(254)))),0) +',    ALQICM = '+ ISNULL(LTRIM(RTRIM(CAST(ALQICM AS CHAR(254)))),0) +',    ALQICM2 = '+ ISNULL(LTRIM(RTRIM(CAST(ALQICM2 AS CHAR(254)))),0) +',    ALQICM3 = '+ ISNULL(LTRIM(RTRIM(CAST(ALQICM3 AS CHAR(254)))),0) +',    VALICM = '+ ISNULL(LTRIM(RTRIM(CAST(VALICM AS CHAR(254)))),0) +',    VALICM2 = '+ ISNULL(LTRIM(RTRIM(CAST(VALICM2 AS CHAR(254)))),0) +',    VALICM3 = '+ ISNULL(LTRIM(RTRIM(CAST(VALICM3 AS CHAR(254)))),0) +',    BASEIPI = '+ ISNULL(LTRIM(RTRIM(CAST(BASEIPI AS CHAR(254)))),0) +',    VALIPI = '+ ISNULL(LTRIM(RTRIM(CAST(VALIPI AS CHAR(254)))),0) +',    VALSEMICM = '+ ISNULL(LTRIM(RTRIM(CAST(VALSEMICM AS CHAR(254)))),0) +',    VALSEMIPI = '+ ISNULL(LTRIM(RTRIM(CAST(VALSEMIPI AS CHAR(254)))),0) +',    BASESTRIB = '+ ISNULL(LTRIM(RTRIM(CAST(BASESTRIB AS CHAR(254)))),0) +',    VALSUBSTRI = '+ ISNULL(LTRIM(RTRIM(CAST(VALSUBSTRI AS CHAR(254)))),0) +',    VALTRIBDIF = '+ ISNULL(LTRIM(RTRIM(CAST(VALTRIBDIF AS CHAR(254)))),0) +',    DESTAQIPI = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(DESTAQIPI AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    VALSERVICO = '+ ISNULL(LTRIM(RTRIM(CAST(VALSERVICO AS CHAR(254)))),0) +',    VALISS = '+ ISNULL(LTRIM(RTRIM(CAST(VALISS AS CHAR(254)))),0) +',    VALFRETE = '+ ISNULL(LTRIM(RTRIM(CAST(VALFRETE AS CHAR(254)))),0) +',    VALSEGURO = '+ ISNULL(LTRIM(RTRIM(CAST(VALSEGURO AS CHAR(254)))),0) +',    FRETEINC = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(FRETEINC AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    OUTRICM = '+ ISNULL(LTRIM(RTRIM(CAST(OUTRICM AS CHAR(254)))),0) +',    OUTRIPI = '+ ISNULL(LTRIM(RTRIM(CAST(OUTRIPI AS CHAR(254)))),0) +',    CCUSTO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CCUSTO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    OBS = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(OBS AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CODVEND = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODVEND AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    NUMPED = '+ ISNULL(LTRIM(RTRIM(CAST(NUMPED AS CHAR(254)))),0) +',    VALENTRAD = '+ ISNULL(LTRIM(RTRIM(CAST(VALENTRAD AS CHAR(254)))),0) +',    CODMETRA = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODMETRA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CODTRAN = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODTRAN AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    DESCONTO = '+ ISNULL(LTRIM(RTRIM(CAST(DESCONTO AS CHAR(254)))),0) +',    COMISSAO = '+ ISNULL(LTRIM(RTRIM(CAST(COMISSAO AS CHAR(254)))),0) +',    FATURADO = '+ ISNULL(LTRIM(RTRIM(CAST(FATURADO AS CHAR(254)))),0) +',    ATUALIZ = '+ ISNULL(LTRIM(RTRIM(CAST(ATUALIZ AS CHAR(254)))),0) +',    FLAGEMIT = '+ ISNULL(LTRIM(RTRIM(CAST(FLAGEMIT AS CHAR(254)))),0) +',    FLAGREGFIS = '+ ISNULL(LTRIM(RTRIM(CAST(FLAGREGFIS AS CHAR(254)))),0) +',    FLAGATUA = '+ ISNULL(LTRIM(RTRIM(CAST(FLAGATUA AS CHAR(254)))),0) +',    ICMSIPI = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ICMSIPI AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    VALEMBA = '+ ISNULL(LTRIM(RTRIM(CAST(VALEMBA AS CHAR(254)))),0) +',    CODROTE = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODROTE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CODNATOP = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(CODNATOP AS CHAR(254)))),0) +'**],    FILTRANSF = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(FILTRANSF AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    TIPONF = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(TIPONF AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    FLAGINTER = '+ ISNULL(LTRIM(RTRIM(CAST(FLAGINTER AS CHAR(254)))),0) +',    FLAGCONTAB = '+ ISNULL(LTRIM(RTRIM(CAST(FLAGCONTAB AS CHAR(254)))),0) +',    CODSITEST = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODSITEST AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CODSITFED = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODSITFED AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    PERCSUBST = '+ ISNULL(LTRIM(RTRIM(CAST(PERCSUBST AS CHAR(254)))),0) +',    LUCRO = '+ ISNULL(LTRIM(RTRIM(CAST(LUCRO AS CHAR(254)))),0) +',    REC = '+ ISNULL(LTRIM(RTRIM(CAST(REC AS CHAR(254)))),0) +',    CXA = '+ ISNULL(LTRIM(RTRIM(CAST(CXA AS CHAR(254)))),0) +',    FLU = '+ ISNULL(LTRIM(RTRIM(CAST(FLU AS CHAR(254)))),0) +',    CTB = '+ ISNULL(LTRIM(RTRIM(CAST(CTB AS CHAR(254)))),0) +',    ATF = '+ ISNULL(LTRIM(RTRIM(CAST(ATF AS CHAR(254)))),0) +',    CUS = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CUS AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    INTEGRADO = '+ ISNULL(LTRIM(RTRIM(CAST(INTEGRADO AS CHAR(254)))),0) +',    DTCANCEL = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DTCANCEL,20)))+''',120)','NULL')+',    BASEISS = '+ ISNULL(LTRIM(RTRIM(CAST(BASEISS AS CHAR(254)))),0) +',    MODELONF = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(MODELONF AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CONDPAG = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(CONDPAG AS CHAR(254)))),0) +'**],    EST = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(EST AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    LIF = '+ ISNULL(LTRIM(RTRIM(CAST(LIF AS CHAR(254)))),0) +',    FAT = '+ ISNULL(LTRIM(RTRIM(CAST(FAT AS CHAR(254)))),0) +',    EXPORTADO = '+ ISNULL(LTRIM(RTRIM(CAST(EXPORTADO AS CHAR(254)))),0) +',    CODMES = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODMES AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    PERIPI = '+ ISNULL(LTRIM(RTRIM(CAST(PERIPI AS CHAR(254)))),0) +',    LOCALPORTA = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(LOCALPORTA AS CHAR(254)))),0) +'**],    CONTA = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(CONTA AS CHAR(254)))),0) +'**],    CODTRAN2 = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODTRAN2 AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    NUMNOTA = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NUMNOTA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    SERIE = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(SERIE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CODCLIE = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(CODCLIE AS CHAR(254)))),0) +'**],    DTEMIS = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DTEMIS,20)))+''',120)','NULL')+',    ESPDOC = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ESPDOC AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    FILIAL = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(FILIAL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    ESTADO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ESTADO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CFO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CFO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    TPO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(TPO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    VALCONTAB = '+ ISNULL(LTRIM(RTRIM(CAST(VALCONTAB AS CHAR(254)))),0) +',    BASEICM = '+ ISNULL(LTRIM(RTRIM(CAST(BASEICM AS CHAR(254)))),0) +',    BASEICM2 = '+ ISNULL(LTRIM(RTRIM(CAST(BASEICM2 AS CHAR(254)))),0) +',    CUPOMINI = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CUPOMINI AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CUPOMFIM = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CUPOMFIM AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    GVE = '+ ISNULL(LTRIM(RTRIM(CAST(GVE AS CHAR(254)))),0) +',    BASEICM4 = '+ ISNULL(LTRIM(RTRIM(CAST(BASEICM4 AS CHAR(254)))),0) +',    ALQICM4 = '+ ISNULL(LTRIM(RTRIM(CAST(ALQICM4 AS CHAR(254)))),0) +',    VALICM4 = '+ ISNULL(LTRIM(RTRIM(CAST(VALICM4 AS CHAR(254)))),0) +',    CLASVEND = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CLASVEND AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    FLAGCONS = '+ ISNULL(LTRIM(RTRIM(CAST(FLAGCONS AS CHAR(254)))),0) +',    CLIFIM = '+ ISNULL(LTRIM(RTRIM(CAST(CLIFIM AS CHAR(254)))),0) +',    EXPORTA = '+ ISNULL(LTRIM(RTRIM(CAST(EXPORTA AS CHAR(254)))),0) +',    PEDIMPO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(PEDIMPO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    TIPONOTA = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(TIPONOTA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    NUMECF = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NUMECF AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    NUMCUPON = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NUMCUPON AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    VALNFCHE = '+ ISNULL(LTRIM(RTRIM(CAST(VALNFCHE AS CHAR(254)))),0) +',    CLIENTEA = '+ ISNULL(LTRIM(RTRIM(CAST(CLIENTEA AS CHAR(254)))),0) +',    NORDVEN = '+ ISNULL(LTRIM(RTRIM(CAST(NORDVEN AS CHAR(254)))),0) +',    NUMNFECF = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NUMNFECF AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    BASEICM5 = '+ ISNULL(LTRIM(RTRIM(CAST(BASEICM5 AS CHAR(254)))),0) +',    ALQICM5 = '+ ISNULL(LTRIM(RTRIM(CAST(ALQICM5 AS CHAR(254)))),0) +',    VALICM5 = '+ ISNULL(LTRIM(RTRIM(CAST(VALICM5 AS CHAR(254)))),0) +',    NUMORDFIS = '+ ISNULL(LTRIM(RTRIM(CAST(NUMORDFIS AS CHAR(254)))),0) +',    IMPOGER = '+ ISNULL(LTRIM(RTRIM(CAST(IMPOGER AS CHAR(254)))),0) +',    ICMSFONTE = '+ ISNULL(LTRIM(RTRIM(CAST(ICMSFONTE AS CHAR(254)))),0) +',    TOTMERC = '+ ISNULL(LTRIM(RTRIM(CAST(TOTMERC AS CHAR(254)))),0) +',    TOTPESO = '+ ISNULL(LTRIM(RTRIM(CAST(TOTPESO AS CHAR(254)))),0) +',    TXFINAN = '+ ISNULL(LTRIM(RTRIM(CAST(TXFINAN AS CHAR(254)))),0) +',    EXCED = '+ ISNULL(LTRIM(RTRIM(CAST(EXCED AS CHAR(254)))),0) +',    CODLIS = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODLIS AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    OIDDOCDEORIGEM = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(OIDDOCDEORIGEM AS CHAR(254)))),0) +'**],    ATUACUM = '+ ISNULL(LTRIM(RTRIM(CAST(ATUACUM AS CHAR(254)))),0) +',    JACOMIS = '+ ISNULL(LTRIM(RTRIM(CAST(JACOMIS AS CHAR(254)))),0) +',    CONTABILIZADO = '+ ISNULL(LTRIM(RTRIM(CAST(CONTABILIZADO AS CHAR(254)))),0) +',    CODFOROUT = '+ ISNULL(LTRIM(RTRIM(CAST(CODFOROUT AS CHAR(254)))),0) +',    DEPORIGEM = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(DEPORIGEM AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    TPOOUTRAENT = '+ ISNULL(LTRIM(RTRIM(CAST(TPOOUTRAENT AS CHAR(254)))),0) +',    CONTREDZ = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CONTREDZ AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    GT = '+ ISNULL(LTRIM(RTRIM(CAST(GT AS CHAR(254)))),0) +',    BASEIR = '+ ISNULL(LTRIM(RTRIM(CAST(BASEIR AS CHAR(254)))),0) +',    ALIQIR = '+ ISNULL(LTRIM(RTRIM(CAST(ALIQIR AS CHAR(254)))),0) +',    CODGER = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODGER AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    OIDREVENDA = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(OIDREVENDA AS CHAR(254)))),0) +'**],    HISTORICO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(HISTORICO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    BASEINSS = '+ ISNULL(LTRIM(RTRIM(CAST(BASEINSS AS CHAR(254)))),0) +',    ALIQINSS = '+ ISNULL(LTRIM(RTRIM(CAST(ALIQINSS AS CHAR(254)))),0) +',    VALINSS = '+ ISNULL(LTRIM(RTRIM(CAST(VALINSS AS CHAR(254)))),0) +',    ALIQISSRET = '+ ISNULL(LTRIM(RTRIM(CAST(ALIQISSRET AS CHAR(254)))),0) +',    BASEISSRET = '+ ISNULL(LTRIM(RTRIM(CAST(BASEISSRET AS CHAR(254)))),0) +',    VALISSRET = '+ ISNULL(LTRIM(RTRIM(CAST(VALISSRET AS CHAR(254)))),0) +',    VALIRRF = '+ ISNULL(LTRIM(RTRIM(CAST(VALIRRF AS CHAR(254)))),0) +',    NFFUTURA = '+ ISNULL(LTRIM(RTRIM(CAST(NFFUTURA AS CHAR(254)))),0) +',    NORDEXPEDIC = '+ ISNULL(LTRIM(RTRIM(CAST(NORDEXPEDIC AS CHAR(254)))),0) +',    VALIDADE = '+ ISNULL(LTRIM(RTRIM(CAST(VALIDADE AS CHAR(254)))),0) +',    SITPRODUTO = '+ ISNULL(LTRIM(RTRIM(CAST(SITPRODUTO AS CHAR(254)))),0) +',    DESPNAOINCLUSAS = '+ ISNULL(LTRIM(RTRIM(CAST(DESPNAOINCLUSAS AS CHAR(254)))),0) +',    ICMSDESPNAOINCLUSAS = '+ ISNULL(LTRIM(RTRIM(CAST(ICMSDESPNAOINCLUSAS AS CHAR(254)))),0) +',    FRETESUBSTRIBUTARIA = '+ ISNULL(LTRIM(RTRIM(CAST(FRETESUBSTRIBUTARIA AS CHAR(254)))),0) +',    SERIEECF = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(SERIEECF AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    GTFIM = '+ ISNULL(LTRIM(RTRIM(CAST(GTFIM AS CHAR(254)))),0) +',    VALCANECF = '+ ISNULL(LTRIM(RTRIM(CAST(VALCANECF AS CHAR(254)))),0) +',    VALDESCECF = '+ ISNULL(LTRIM(RTRIM(CAST(VALDESCECF AS CHAR(254)))),0) +',    CONTREIOPE = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CONTREIOPE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    NUMORDECF = '+ ISNULL(LTRIM(RTRIM(CAST(NUMORDECF AS CHAR(254)))),0) +',    OUTRASDESPESASINCLUSAS = '+ ISNULL(LTRIM(RTRIM(CAST(OUTRASDESPESASINCLUSAS AS CHAR(254)))),0) +',    TIPOENTR = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(TIPOENTR AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    TOTALVALORICMS = '+ ISNULL(LTRIM(RTRIM(CAST(TOTALVALORICMS AS CHAR(254)))),0) +',    TOTALPRECOCOMICMS = '+ ISNULL(LTRIM(RTRIM(CAST(TOTALPRECOCOMICMS AS CHAR(254)))),0) +',    DESPESASIMPORTACAO = '+ ISNULL(LTRIM(RTRIM(CAST(DESPESASIMPORTACAO AS CHAR(254)))),0) +',    OIDSERIALECF = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(OIDSERIALECF AS CHAR(254)))),0) +'**]'+  ' WHERE numord = '+ RTRIM(CAST(numord as char(254))) +  ''   , 'NFSAIDACAD' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'NOTA_ELETRONICA_XML_D' AND type = 'TR')
  drop trigger NOTA_ELETRONICA_XML_D
go
create trigger dbo.NOTA_ELETRONICA_XML_D on dbo.NOTA_ELETRONICA_XML for delete as
    Begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
            SELECT getdate(), null,'DELETE FROM NOTA_ELETRONICA_XML WHERE 
NUMORD = '+ RTRIM(LTRIM(CAST(NUMORD as char(120)))) + ' ','NOTA_ELETRONICA_XML' from deleted
    End
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'NOTA_ELETRONICA_XML_I' AND type = 'TR')
   drop trigger NOTA_ELETRONICA_XML_I
go
create trigger dbo.NOTA_ELETRONICA_XML_I on dbo.NOTA_ELETRONICA_XML for insert as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
    SELECT getdate(), null,'INSERT INTO NOTA_ELETRONICA_XML(
        DATA,    NUMORD,    TIPO_OPERACAO,    CHAVE_SEF,    NOME_ARQUIVO)
    VALUES (
    '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DATA,20 ))) +''',120)','NULL')+','+ ISNULL(LTRIM(RTRIM(CAST(NUMORD AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(TIPO_OPERACAO AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CHAVE_SEF AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NOME_ARQUIVO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''')
     '+ ')', 'NOTA_ELETRONICA_XML' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'OBSAIDALIF_D' AND type = 'TR')
  drop trigger OBSAIDALIF_D
go
create trigger dbo.OBSAIDALIF_D on dbo.OBSAIDALIF for delete as
    Begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
            SELECT getdate(), null,'DELETE FROM OBSAIDALIF WHERE 
filial = '''+ RTRIM(LTRIM(filial)) + '''  and numnota = '''+ RTRIM(LTRIM(numnota)) + '''  and serie = '''+ RTRIM(LTRIM(serie)) + ''' ','OBSAIDALIF' from deleted
    End
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'OBSAIDALIF_I' AND type = 'TR')
   drop trigger OBSAIDALIF_I
go
create trigger dbo.OBSAIDALIF_I on dbo.OBSAIDALIF for insert as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
    SELECT getdate(), null,'INSERT INTO OBSAIDALIF(
        FILIAL,    NUMNOTA,    SERIE,    CODCLIE,    OBSERVACAO)
    VALUES (
    '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(FILIAL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NUMNOTA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(SERIE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',  [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(CODCLIE AS CHAR(254)))),0) +'**],'''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(OBSERVACAO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +'''
     '+ ')', 'OBSAIDALIF' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'OBSAIDALIF_U' AND type = 'TR')
   drop trigger OBSAIDALIF_U
go
create trigger dbo.OBSAIDALIF_U on dbo.OBSAIDALIF for update as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )    SELECT getdate(), null,'UPDATE OBSAIDALIF SET     CODCLIE = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(CODCLIE AS CHAR(254)))),0) +'**],    OBSERVACAO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(OBSERVACAO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''''+  ' WHERE filial = '''+ RTRIM(filial)  + ''' and numnota = '''+ RTRIM(numnota)  + ''' and serie = '''+ RTRIM(serie)  + ''''   , 'OBSAIDALIF' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'OBSERVALIF_D' AND type = 'TR')
  drop trigger OBSERVALIF_D
go
create trigger dbo.OBSERVALIF_D on dbo.OBSERVALIF for delete as
    Begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
            SELECT getdate(), null,'DELETE FROM OBSERVALIF WHERE 
numord = '+ RTRIM(LTRIM(CAST(numord as char(120)))) + ' ','OBSERVALIF' from deleted
    End
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'OBSERVALIF_I' AND type = 'TR')
   drop trigger OBSERVALIF_I
go
create trigger dbo.OBSERVALIF_I on dbo.OBSERVALIF for insert as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
    SELECT getdate(), null,'INSERT INTO OBSERVALIF(
        NUMORD,    TIPO,    OBSERVACAO,    NUMORDFIS,    IMPOGER,    CFO)
    VALUES (
    '+ ISNULL(LTRIM(RTRIM(CAST(NUMORD AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(TIPO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(OBSERVACAO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(NUMORDFIS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(IMPOGER AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CFO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +'''
     '+ ')', 'OBSERVALIF' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'OBSERVALIF_U' AND type = 'TR')
   drop trigger OBSERVALIF_U
go
create trigger dbo.OBSERVALIF_U on dbo.OBSERVALIF for update as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )    SELECT getdate(), null,'UPDATE OBSERVALIF SET     TIPO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(TIPO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    OBSERVACAO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(OBSERVACAO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    NUMORDFIS = '+ ISNULL(LTRIM(RTRIM(CAST(NUMORDFIS AS CHAR(254)))),0) +',    IMPOGER = '+ ISNULL(LTRIM(RTRIM(CAST(IMPOGER AS CHAR(254)))),0) +',    CFO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CFO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''''+  ' WHERE numord = '+ RTRIM(CAST(numord as char(254))) +  ''   , 'OBSERVALIF' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'ORDEMSEPARACAO_D' AND type = 'TR')
  drop trigger ORDEMSEPARACAO_D
go
create trigger dbo.ORDEMSEPARACAO_D on dbo.ORDEMSEPARACAO for delete as
    Begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
            SELECT getdate(), null,'DELETE FROM ORDEMSEPARACAO WHERE 
Filial = '''+ RTRIM(LTRIM(Filial)) + '''  and NumPed = '+ RTRIM(LTRIM(CAST(NumPed as char(120)))) + '  and CodPro = '''+ RTRIM(LTRIM(CodPro)) + '''  and LoteInterno = '''+ RTRIM(LTRIM(LoteInterno)) + '''  and ReservadoPor = '''+ RTRIM(LTRIM(ReservadoPor)) + '''  and RItem = '+ RTRIM(LTRIM(CAST(RItem as char(120)))) + '  and NumOrd = '+ RTRIM(LTRIM(CAST(NumOrd as char(120)))) + ' ','ORDEMSEPARACAO' from deleted
    End
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'ORDEMSEPARACAO_I' AND type = 'TR')
   drop trigger ORDEMSEPARACAO_I
go
create trigger dbo.ORDEMSEPARACAO_I on dbo.ORDEMSEPARACAO for insert as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
    SELECT getdate(), null,'INSERT INTO ORDEMSEPARACAO(
        FILIAL,    NUMPED,    CODPRO,    LOTEINTERNO,    QUANT,    RESERVADOPOR,    RITEM,    NUMORD)
    VALUES (
    '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(FILIAL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(NUMPED AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODPRO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LOTEINTERNO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(QUANT AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(RESERVADOPOR AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(RITEM AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(NUMORD AS CHAR(254)))),0) +'
     '+ ')', 'ORDEMSEPARACAO' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'ORDEMSEPARACAO_U' AND type = 'TR')
   drop trigger ORDEMSEPARACAO_U
go
create trigger dbo.ORDEMSEPARACAO_U on dbo.ORDEMSEPARACAO for update as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )    SELECT getdate(), null,'UPDATE ORDEMSEPARACAO SET     QUANT = '+ ISNULL(LTRIM(RTRIM(CAST(QUANT AS CHAR(254)))),0) +''+  ' WHERE Filial = '''+ RTRIM(Filial)  + ''' and NumPed = '+ RTRIM(CAST(NumPed as char(254))) +  ' and CodPro = '''+ RTRIM(CodPro)  + ''' and LoteInterno = '''+ RTRIM(LoteInterno)  + ''' and ReservadoPor = '''+ RTRIM(ReservadoPor)  + ''' and RItem = '+ RTRIM(CAST(RItem as char(254))) +  ' and NumOrd = '+ RTRIM(CAST(NumOrd as char(254))) +  ''   , 'ORDEMSEPARACAO' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'PEDICLICAD_D' AND type = 'TR')
  drop trigger PEDICLICAD_D
go
create trigger dbo.PEDICLICAD_D on dbo.PEDICLICAD for delete as
    Begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
            SELECT getdate(), null,'DELETE FROM PEDICLICAD WHERE 
numped = '+ RTRIM(LTRIM(CAST(numped as char(120)))) + '  and filial = '''+ RTRIM(LTRIM(filial)) + ''' ','PEDICLICAD' from deleted
    End
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'PEDICLICAD_I' AND type = 'TR')
   drop trigger PEDICLICAD_I
go
create trigger dbo.PEDICLICAD_I on dbo.PEDICLICAD for insert as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
    SELECT getdate(), null,'INSERT INTO PEDICLICAD(
        DTPRIPAG,    DTPEDIDO,    OBS,    NUMORD,    TPO,    FILIAL,    REFERENCIA,    MOEDCOR,    DATAATU,    ORDPROD,    PERFRETE,    VALFRETE,    PERSEGURO,    VALSEGURO,    RAZAOCLI,    ENDERCLI,    BAIRRCLI,    CIDADCLI,    CEPCLI,    CGCCLI,    INSCLI,    ESTCLI,    TIPNOTA,    CODTRAN,    CODTRAN2,    CODENDENT,    CODENDCOB,    OBSERV,    FILIALCLI,    RESPCLI,    RESPFOR,    TPOENT,    SITUACAO,    NUMPEDFIL,    ATUAREC,    NUMROM,    PENDENTE,    LIBDESC,    LIBCRED,    LIBLIMI,    LIBBLOQ,    LIBATRA,    SITVEN,    NAOAPROV,    TELECLI,    HORAPED,    FRETEORC,    NUMFRETE,    USUCRED,    CREDITO,    LIBFORM,    RFORMADEPAGAR,    CODLIS,    TIPOFRETE,    CODROTE,    SITCONF,    NUMCLIE,    CONTRIBCLIE,    FILIALVEND,    DESTINO,    CODMENS,    TRIBUTADO,    INSCSUFRACLI,    COMPLCLI,    SITMANUT,    CODFOROUT,    DEPORIGEM,    TPOOUTRAENT,    CQUALIDADE,    REFQUALIDADE,    CONDPAGPOSTERIOR,    ETAPA,    VALORFAT,    VALORREC,    TAXANF,    RECEBER,    TIPOVENDA,    OIDREVENDA,    SITMON,    TEMCONJUNTO,    TXREVENDA,    SITCRED,    FLAGEMIT,    SITSAGA,    NUMPED,    CODCLIE,    NUMORC,    CODVEND,    VALPED,    VALENTRAD,    DESCONTO,    DTPREVENT,    CONDPAG,    DTVALIDADE,    OIDCONTATO,    LIBTPDOC,    APELIDO,    CONTATO,    PERDESCTO,    RESERVACONJUNTO,    VIAMONT,    RCARENCIAPARCELA,    RDOCPLANO,    RDOCENTRADA,    ARQUIVOCDL,    TEMSEGURO,    PLANOSEMJUROS,    FATOREMPRESA,    DESMEMBRADO,    LIBFRETE,    LIBMARKMIN,    LIBPRAZOMEDIO,    OUTRASDESPESASINCLUSAS,    PERCIPISEGURO,    PRAZOMEDIO,    URGENTE,    VALPEDTX,    VIAORCAMENTO,    VIAORDEMSEPARACAO,    ORGAOPUBCLIE,    ENDERECOFATURA,    CONTRATO,    EMPENHO)
    VALUES (
    '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DTPRIPAG,20 ))) +''',120)','NULL')+','+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DTPEDIDO,20 ))) +''',120)','NULL')+','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(OBS AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(NUMORD AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(TPO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(FILIAL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(REFERENCIA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(MOEDCOR AS CHAR(254)))),0) +','+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DATAATU,20 ))) +''',120)','NULL')+','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ORDPROD AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(PERFRETE AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALFRETE AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(PERSEGURO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALSEGURO AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(RAZAOCLI AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ENDERCLI AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(BAIRRCLI AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CIDADCLI AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CEPCLI AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CGCCLI AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(INSCLI AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ESTCLI AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(TIPNOTA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODTRAN AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODTRAN2 AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',  [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(CODENDENT AS CHAR(254)))),0) +'**],  [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(CODENDCOB AS CHAR(254)))),0) +'**],'''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(OBSERV AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(FILIALCLI AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(RESPCLI AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(RESPFOR AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(TPOENT AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(SITUACAO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NUMPEDFIL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(ATUAREC AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NUMROM AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(PENDENTE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LIBDESC AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LIBCRED AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LIBLIMI AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LIBBLOQ AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LIBATRA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(SITVEN AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NAOAPROV AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(TELECLI AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(HORAPED AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(FRETEORC AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NUMFRETE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(USUCRED AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(CREDITO AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LIBFORM AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',  [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(RFORMADEPAGAR AS CHAR(254)))),0) +'**],'''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODLIS AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(TIPOFRETE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODROTE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(SITCONF AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NUMCLIE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CONTRIBCLIE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(FILIALVEND AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(DESTINO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODMENS AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(TRIBUTADO AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(INSCSUFRACLI AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(COMPLCLI AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(SITMANUT AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(CODFOROUT AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(DEPORIGEM AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(TPOOUTRAENT AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(CQUALIDADE AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(REFQUALIDADE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',  [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(CONDPAGPOSTERIOR AS CHAR(254)))),0) +'**],'+ ISNULL(LTRIM(RTRIM(CAST(ETAPA AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALORFAT AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALORREC AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(TAXANF AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(RECEBER AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(TIPOVENDA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',  [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(OIDREVENDA AS CHAR(254)))),0) +'**],'''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(SITMON AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(TEMCONJUNTO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(TXREVENDA AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(SITCRED AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(FLAGEMIT AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(SITSAGA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(NUMPED AS CHAR(254)))),0) +',  [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(CODCLIE AS CHAR(254)))),0) +'**],'''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NUMORC AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODVEND AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(VALPED AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALENTRAD AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(DESCONTO AS CHAR(254)))),0) +','+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DTPREVENT,20 ))) +''',120)','NULL')+',  [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(CONDPAG AS CHAR(254)))),0) +'**],'+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DTVALIDADE,20 ))) +''',120)','NULL')+',  [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(OIDCONTATO AS CHAR(254)))),0) +'**],'''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LIBTPDOC AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(APELIDO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CONTATO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(PERDESCTO AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(RESERVACONJUNTO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(VIAMONT AS CHAR(254)))),0) +',  [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(RCARENCIAPARCELA AS CHAR(254)))),0) +'**],  [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(RDOCPLANO AS CHAR(254)))),0) +'**],  [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(RDOCENTRADA AS CHAR(254)))),0) +'**],'''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ARQUIVOCDL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(TEMSEGURO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(PLANOSEMJUROS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(FATOREMPRESA AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(DESMEMBRADO AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LIBFRETE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LIBMARKMIN AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LIBPRAZOMEDIO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(OUTRASDESPESASINCLUSAS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(PERCIPISEGURO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(PRAZOMEDIO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(URGENTE AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALPEDTX AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VIAORCAMENTO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VIAORDEMSEPARACAO AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ORGAOPUBCLIE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ENDERECOFATURA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(CONTRATO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(EMPENHO AS CHAR(254)))),0) +'
     '+ ')', 'PEDICLICAD' FROM inserted
    UPDATE VENDEDOCAD SET ULT_NUMPED = (select Numped  from inserted) WHERE CODVEND = (select CodVend from inserted)
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'PEDICLICAD_U' AND type = 'TR')
   drop trigger PEDICLICAD_U
go
create trigger dbo.PEDICLICAD_U on dbo.PEDICLICAD for update as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )    SELECT getdate(), null,'UPDATE PEDICLICAD SET     DTPRIPAG = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DTPRIPAG,20)))+''',120)','NULL')+',    DTPEDIDO = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DTPEDIDO,20)))+''',120)','NULL')+',    OBS = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(OBS AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    NUMORD = '+ ISNULL(LTRIM(RTRIM(CAST(NUMORD AS CHAR(254)))),0) +',    TPO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(TPO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    REFERENCIA = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(REFERENCIA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    MOEDCOR = '+ ISNULL(LTRIM(RTRIM(CAST(MOEDCOR AS CHAR(254)))),0) +',    DATAATU = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DATAATU,20)))+''',120)','NULL')+',    ORDPROD = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ORDPROD AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    PERFRETE = '+ ISNULL(LTRIM(RTRIM(CAST(PERFRETE AS CHAR(254)))),0) +',    VALFRETE = '+ ISNULL(LTRIM(RTRIM(CAST(VALFRETE AS CHAR(254)))),0) +',    PERSEGURO = '+ ISNULL(LTRIM(RTRIM(CAST(PERSEGURO AS CHAR(254)))),0) +',    VALSEGURO = '+ ISNULL(LTRIM(RTRIM(CAST(VALSEGURO AS CHAR(254)))),0) +',    RAZAOCLI = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(RAZAOCLI AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    ENDERCLI = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ENDERCLI AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    BAIRRCLI = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(BAIRRCLI AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CIDADCLI = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CIDADCLI AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CEPCLI = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CEPCLI AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CGCCLI = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CGCCLI AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    INSCLI = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(INSCLI AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    ESTCLI = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ESTCLI AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    TIPNOTA = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(TIPNOTA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CODTRAN = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODTRAN AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CODTRAN2 = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODTRAN2 AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CODENDENT = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(CODENDENT AS CHAR(254)))),0) +'**],    CODENDCOB = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(CODENDCOB AS CHAR(254)))),0) +'**],    OBSERV = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(OBSERV AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    FILIALCLI = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(FILIALCLI AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    RESPCLI = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(RESPCLI AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    RESPFOR = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(RESPFOR AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    TPOENT = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(TPOENT AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    SITUACAO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(SITUACAO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    NUMPEDFIL = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NUMPEDFIL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    ATUAREC = '+ ISNULL(LTRIM(RTRIM(CAST(ATUAREC AS CHAR(254)))),0) +',    NUMROM = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NUMROM AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    PENDENTE = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(PENDENTE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    LIBDESC = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LIBDESC AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    LIBCRED = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LIBCRED AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    LIBLIMI = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LIBLIMI AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    LIBBLOQ = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LIBBLOQ AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    LIBATRA = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LIBATRA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    SITVEN = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(SITVEN AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    NAOAPROV = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NAOAPROV AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    TELECLI = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(TELECLI AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    HORAPED = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(HORAPED AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    FRETEORC = '+ ISNULL(LTRIM(RTRIM(CAST(FRETEORC AS CHAR(254)))),0) +',    NUMFRETE = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NUMFRETE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    USUCRED = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(USUCRED AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CREDITO = '+ ISNULL(LTRIM(RTRIM(CAST(CREDITO AS CHAR(254)))),0) +',    LIBFORM = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LIBFORM AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    RFORMADEPAGAR = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(RFORMADEPAGAR AS CHAR(254)))),0) +'**],    CODLIS = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODLIS AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    TIPOFRETE = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(TIPOFRETE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CODROTE = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODROTE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    SITCONF = '+ ISNULL(LTRIM(RTRIM(CAST(SITCONF AS CHAR(254)))),0) +',    NUMCLIE = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NUMCLIE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CONTRIBCLIE = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CONTRIBCLIE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    FILIALVEND = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(FILIALVEND AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    DESTINO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(DESTINO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CODMENS = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODMENS AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    TRIBUTADO = '+ ISNULL(LTRIM(RTRIM(CAST(TRIBUTADO AS CHAR(254)))),0) +',    INSCSUFRACLI = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(INSCSUFRACLI AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    COMPLCLI = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(COMPLCLI AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    SITMANUT = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(SITMANUT AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CODFOROUT = '+ ISNULL(LTRIM(RTRIM(CAST(CODFOROUT AS CHAR(254)))),0) +',    DEPORIGEM = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(DEPORIGEM AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    TPOOUTRAENT = '+ ISNULL(LTRIM(RTRIM(CAST(TPOOUTRAENT AS CHAR(254)))),0) +',    CQUALIDADE = '+ ISNULL(LTRIM(RTRIM(CAST(CQUALIDADE AS CHAR(254)))),0) +',    REFQUALIDADE = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(REFQUALIDADE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CONDPAGPOSTERIOR = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(CONDPAGPOSTERIOR AS CHAR(254)))),0) +'**],    ETAPA = '+ ISNULL(LTRIM(RTRIM(CAST(ETAPA AS CHAR(254)))),0) +',    VALORFAT = '+ ISNULL(LTRIM(RTRIM(CAST(VALORFAT AS CHAR(254)))),0) +',    VALORREC = '+ ISNULL(LTRIM(RTRIM(CAST(VALORREC AS CHAR(254)))),0) +',    TAXANF = '+ ISNULL(LTRIM(RTRIM(CAST(TAXANF AS CHAR(254)))),0) +',    RECEBER = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(RECEBER AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    TIPOVENDA = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(TIPOVENDA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    OIDREVENDA = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(OIDREVENDA AS CHAR(254)))),0) +'**],    SITMON = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(SITMON AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    TEMCONJUNTO = '+ ISNULL(LTRIM(RTRIM(CAST(TEMCONJUNTO AS CHAR(254)))),0) +',    TXREVENDA = '+ ISNULL(LTRIM(RTRIM(CAST(TXREVENDA AS CHAR(254)))),0) +',    SITCRED = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(SITCRED AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    FLAGEMIT = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(FLAGEMIT AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    SITSAGA = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(SITSAGA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CODCLIE = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(CODCLIE AS CHAR(254)))),0) +'**],    NUMORC = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NUMORC AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CODVEND = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODVEND AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    VALPED = '+ ISNULL(LTRIM(RTRIM(CAST(VALPED AS CHAR(254)))),0) +',    VALENTRAD = '+ ISNULL(LTRIM(RTRIM(CAST(VALENTRAD AS CHAR(254)))),0) +',    DESCONTO = '+ ISNULL(LTRIM(RTRIM(CAST(DESCONTO AS CHAR(254)))),0) +',    DTPREVENT = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DTPREVENT,20)))+''',120)','NULL')+',    CONDPAG = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(CONDPAG AS CHAR(254)))),0) +'**],    DTVALIDADE = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DTVALIDADE,20)))+''',120)','NULL')+',    OIDCONTATO = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(OIDCONTATO AS CHAR(254)))),0) +'**],    LIBTPDOC = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LIBTPDOC AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    APELIDO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(APELIDO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CONTATO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CONTATO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    PERDESCTO = '+ ISNULL(LTRIM(RTRIM(CAST(PERDESCTO AS CHAR(254)))),0) +',    RESERVACONJUNTO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(RESERVACONJUNTO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    VIAMONT = '+ ISNULL(LTRIM(RTRIM(CAST(VIAMONT AS CHAR(254)))),0) +',    RCARENCIAPARCELA = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(RCARENCIAPARCELA AS CHAR(254)))),0) +'**],    RDOCPLANO = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(RDOCPLANO AS CHAR(254)))),0) +'**],    RDOCENTRADA = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(RDOCENTRADA AS CHAR(254)))),0) +'**],    ARQUIVOCDL = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ARQUIVOCDL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    TEMSEGURO = '+ ISNULL(LTRIM(RTRIM(CAST(TEMSEGURO AS CHAR(254)))),0) +',    PLANOSEMJUROS = '+ ISNULL(LTRIM(RTRIM(CAST(PLANOSEMJUROS AS CHAR(254)))),0) +',    FATOREMPRESA = '+ ISNULL(LTRIM(RTRIM(CAST(FATOREMPRESA AS CHAR(254)))),0) +',    DESMEMBRADO = '+ ISNULL(LTRIM(RTRIM(CAST(DESMEMBRADO AS CHAR(254)))),0) +',    LIBFRETE = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LIBFRETE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    LIBMARKMIN = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LIBMARKMIN AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    LIBPRAZOMEDIO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LIBPRAZOMEDIO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    OUTRASDESPESASINCLUSAS = '+ ISNULL(LTRIM(RTRIM(CAST(OUTRASDESPESASINCLUSAS AS CHAR(254)))),0) +',    PERCIPISEGURO = '+ ISNULL(LTRIM(RTRIM(CAST(PERCIPISEGURO AS CHAR(254)))),0) +',    PRAZOMEDIO = '+ ISNULL(LTRIM(RTRIM(CAST(PRAZOMEDIO AS CHAR(254)))),0) +',    URGENTE = '+ ISNULL(LTRIM(RTRIM(CAST(URGENTE AS CHAR(254)))),0) +',    VALPEDTX = '+ ISNULL(LTRIM(RTRIM(CAST(VALPEDTX AS CHAR(254)))),0) +',    VIAORCAMENTO = '+ ISNULL(LTRIM(RTRIM(CAST(VIAORCAMENTO AS CHAR(254)))),0) +',    VIAORDEMSEPARACAO = '+ ISNULL(LTRIM(RTRIM(CAST(VIAORDEMSEPARACAO AS CHAR(254)))),0) +',    ORGAOPUBCLIE = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ORGAOPUBCLIE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    ENDERECOFATURA = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ENDERECOFATURA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CONTRATO = '+ ISNULL(LTRIM(RTRIM(CAST(CONTRATO AS CHAR(254)))),0) +',    EMPENHO = '+ ISNULL(LTRIM(RTRIM(CAST(EMPENHO AS CHAR(254)))),0) +''+  ' WHERE numped = '+ RTRIM(CAST(numped as char(254))) +  ' and filial = '''+ RTRIM(filial)  + ''''   , 'PEDICLICAD' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'PEDICLICOMPLEMENTO_D' AND type = 'TR')
  drop trigger PEDICLICOMPLEMENTO_D
go
create trigger dbo.PEDICLICOMPLEMENTO_D on dbo.PEDICLICOMPLEMENTO for delete as
    Begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
            SELECT getdate(), null,'DELETE FROM PEDICLICOMPLEMENTO WHERE 
NUMPED = '+ RTRIM(LTRIM(CAST(NUMPED as char(120)))) + ' ','PEDICLICOMPLEMENTO' from deleted
    End
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'PEDICLICOMPLEMENTO_I' AND type = 'TR')
   drop trigger PEDICLICOMPLEMENTO_I
go
create trigger dbo.PEDICLICOMPLEMENTO_I on dbo.PEDICLICOMPLEMENTO for insert as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
    SELECT getdate(), null,'INSERT INTO PEDICLICOMPLEMENTO(
        AGREGAFRETE,    CODIGOREGIAO,    CONSIGNACAO,    DESCONTOITENS,    DESCONTOMOEDA2,    DESCTOINFORMADOFORMADEPAGAR,    DESCTOINFORMADOTIPOFRETE,    DESCTOINFORMADOTOTALPEDIDO,    FRETEORCMOEDA2,    FRETEPAGAR,    KMATUAL,    KMMES,    MOEDA,    MOTIVOCANCELAMENTO,    NUMPED,    OBSERVACAOCREDIARIO,    OIDCONTRATANTE,    PLACA,    SEMCONSOLIDACAO,    TABELAPRECOAUXILIAR,    TIPOUSUARIO,    VALPEDMOEDA2,    VALSEGUROMOEDA2,    LIBORCOUTRVEN,    MARKUPREALTOTAL,    RSEGURO,    ENTREGAPOSTERIOR,    LIBENTREGAPOSTERIOR,    DIFERENCAPEDIDOEXTERNO,    VENDAESPECIAL,    FORMAPAGAMENTOCOMISSAO,    TIPODOCUMENTOCOMISSAO,    DATAMARCADA,    TURNO,    RBAIRRO,    CLASSE,    VALCUSTOFRETE,    TEF_ATIVO,    LIBDESCPAGTOCLIENTE,    MEIODEDIVULGACAO,    PERCDESCADICIONALPRODEMOFERTA,    PERCDESCADICIONALPRODSEMOFERTA,    COPIAPEDIDO,    DTPREVISAOFATURAMENTO,    REFERENCIAENDERECO,    DTPRIMEIRAPARCELA,    OBSERVACAONF,    OBSNFTEXTOLIVRE,    LIBTRANSPORTADORA,    LIBPARCELAMINIMACARTAO,    OIDPESSOAAUTORIZADA,    LIBPESSOAAUTORIZADA,    NUMPEDGERADO,    LIBPESODIVERGENTE,    NUMDAV,    LIBORCTOESPECIAL,    SIMPLESFATURAMENTO,    LIBTABPRECO,    MANTERRESERVA,    LIBMANTERRESERVA,    RSESSAODEUSO,    NUMEROCUPOM,    VALORICMSDISPENSADO,    FILIALESTOQUE,    LIBORCTORECANTECIPADO,    DTLIBORCRECANTECIPADO,    NUMPEDTRANSF,    LIBPRECOMINIMO,    LIBAUTELETRONICA,    TOKENCELREF,    ULTCODSENCEL,    NUMEROLISTA,    ENTREGAEXPRESSA,    PERCFRETE,    LIBRESERVA,    LIBCHEQUE,    LIBRECENTREGA,    LIBFRETEINFERIOR,    LIBRECEBENAENTREGA,    LIBTIPOTRANSPORTE,    CODENDSEG,    CLIENTESOLIDARIO,    DESCONTOSUFRAMA,    EMAIL,    ALTERACAO,    IMPRESSAO,    VALDESCONTOFRETE,    LIBLOTERESERVADO,    LIBCLIVEN,    LIBVENFUTDOCDEV,    LIBFILIALPREFERENCIAL,    RECALCULARVENCIMENTO,    MERCADORIAREVENDA,    OBSPENDENCIA,    PENDENCIADOCUMENTOS,    RSEPARADOR,    RCONFERENTE,    LIBBLOQUEIOPRODTRANSP,    VENDAPARACAEMG,    ACRESCIMOFINANCEIRO,    TAXAACRESCIMOFINANCEIRO,    SENHAALTERARACRESCIMO,    ENDERECOFAT,    BAIRROFAT,    COMPLEMENTOFAT,    NUMEROFAT,    CEPFAT,    CIDADEFAT,    ESTADOFAT,    REFERENCIAFAT,    EXPORTADO,    LIBALTERACAODEPOSITOINTERNO,    OIDSEGMENTO,    AREADEVENDAS,    USULIBPENDPLANOBASE,    VENDEDORDESDOBRAMENTO,    DESCONTOIMPORTADOS,    PERCDESCONTOIMPORTADOS,    CCFDAV,    SERIALECFDAV,    COODAV,    DTEMISDAV,    VALORDESCONTOPISCOFINS,    CODENDFAT,    NUMPEDIMPORTADO,    FINALIDADE,    CODVENDINTERNO,    LIBDESCTOITEMOFERTA,    LIBFATTIPODOCRESTRITO,    PONTUACAOPROFISSIONAL,    COMISSAOPROFISSIONAL,    LIBSEMENDERECOCOBRANCA,    LIBALTERACAOPRECOUNITARIO,    LIBVALORCHEQUEACIMAPERMITIDO,    VALORDESCONTOMAXIMOFORMAPAGTO,    LIBPARCELAMINIMA,    OIDSERIALECF,    INTEGRASAGA,    LIBEMISSAOBOLETO,    DAVCANCELADO,    IMPRIMIUNFMANUAL,    LIBULTIMASENHA,    TIPORECEBIMENTO,    LIBALTVALSERVICO,    BLOQUEIADESDOBRAMENTO,    LIBALTERAPRECOOFERTA,    DESCONTOPORPERCENTUAL)
    VALUES (
    '+ ISNULL(LTRIM(RTRIM(CAST(AGREGAFRETE AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(CODIGOREGIAO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(CONSIGNACAO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(DESCONTOITENS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(DESCONTOMOEDA2 AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(DESCTOINFORMADOFORMADEPAGAR AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(DESCTOINFORMADOTIPOFRETE AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(DESCTOINFORMADOTOTALPEDIDO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(FRETEORCMOEDA2 AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(FRETEPAGAR AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(KMATUAL AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(KMMES AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(MOEDA AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(MOTIVOCANCELAMENTO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(NUMPED AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(OBSERVACAOCREDIARIO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',  [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(OIDCONTRATANTE AS CHAR(254)))),0) +'**],'''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(PLACA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(SEMCONSOLIDACAO AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(TABELAPRECOAUXILIAR AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(TIPOUSUARIO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(VALPEDMOEDA2 AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALSEGUROMOEDA2 AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LIBORCOUTRVEN AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(MARKUPREALTOTAL AS CHAR(254)))),0) +',  [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(RSEGURO AS CHAR(254)))),0) +'**],'+ ISNULL(LTRIM(RTRIM(CAST(ENTREGAPOSTERIOR AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LIBENTREGAPOSTERIOR AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(DIFERENCAPEDIDOEXTERNO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VENDAESPECIAL AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(FORMAPAGAMENTOCOMISSAO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(TIPODOCUMENTOCOMISSAO AS CHAR(254)))),0) +','+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DATAMARCADA,20 ))) +''',120)','NULL')+','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(TURNO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(RBAIRRO AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CLASSE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(VALCUSTOFRETE AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(TEF_ATIVO AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LIBDESCPAGTOCLIENTE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(MEIODEDIVULGACAO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(PERCDESCADICIONALPRODEMOFERTA AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(PERCDESCADICIONALPRODSEMOFERTA AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(COPIAPEDIDO AS CHAR(254)))),0) +','+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DTPREVISAOFATURAMENTO,20 ))) +''',120)','NULL')+','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(REFERENCIAENDERECO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DTPRIMEIRAPARCELA,20 ))) +''',120)','NULL')+','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(OBSERVACAONF AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(OBSNFTEXTOLIVRE AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LIBTRANSPORTADORA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LIBPARCELAMINIMACARTAO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',  [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(OIDPESSOAAUTORIZADA AS CHAR(254)))),0) +'**],'''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LIBPESSOAAUTORIZADA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(NUMPEDGERADO AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LIBPESODIVERGENTE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NUMDAV AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LIBORCTOESPECIAL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(SIMPLESFATURAMENTO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(LIBTABPRECO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(MANTERRESERVA AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LIBMANTERRESERVA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(RSESSAODEUSO AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NUMEROCUPOM AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(VALORICMSDISPENSADO AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(FILIALESTOQUE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LIBORCTORECANTECIPADO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DTLIBORCRECANTECIPADO,20 ))) +''',120)','NULL')+','+ ISNULL(LTRIM(RTRIM(CAST(NUMPEDTRANSF AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LIBPRECOMINIMO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LIBAUTELETRONICA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(TOKENCELREF AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ULTCODSENCEL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(NUMEROLISTA AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ENTREGAEXPRESSA AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(PERCFRETE AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LIBRESERVA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LIBCHEQUE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LIBRECENTREGA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LIBFRETEINFERIOR AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LIBRECEBENAENTREGA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LIBTIPOTRANSPORTE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(CODENDSEG AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(CLIENTESOLIDARIO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(DESCONTOSUFRAMA AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(EMAIL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(ALTERACAO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(IMPRESSAO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALDESCONTOFRETE AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LIBLOTERESERVADO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LIBCLIVEN AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LIBVENFUTDOCDEV AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LIBFILIALPREFERENCIAL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(RECALCULARVENCIMENTO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(MERCADORIAREVENDA AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(OBSPENDENCIA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(PENDENCIADOCUMENTOS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(RSEPARADOR AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(RCONFERENTE AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LIBBLOQUEIOPRODTRANSP AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(VENDAPARACAEMG AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ACRESCIMOFINANCEIRO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(TAXAACRESCIMOFINANCEIRO AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(SENHAALTERARACRESCIMO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ENDERECOFAT AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(BAIRROFAT AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(COMPLEMENTOFAT AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NUMEROFAT AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CEPFAT AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CIDADEFAT AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ESTADOFAT AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(REFERENCIAFAT AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(EXPORTADO AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LIBALTERACAODEPOSITOINTERNO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',  [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(OIDSEGMENTO AS CHAR(254)))),0) +'**],'+ ISNULL(LTRIM(RTRIM(CAST(AREADEVENDAS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(USULIBPENDPLANOBASE AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(VENDEDORDESDOBRAMENTO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(DESCONTOIMPORTADOS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(PERCDESCONTOIMPORTADOS AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CCFDAV AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(SERIALECFDAV AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(COODAV AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DTEMISDAV,20 ))) +''',120)','NULL')+','+ ISNULL(LTRIM(RTRIM(CAST(VALORDESCONTOPISCOFINS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(CODENDFAT AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(NUMPEDIMPORTADO AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(FINALIDADE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODVENDINTERNO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LIBDESCTOITEMOFERTA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LIBFATTIPODOCRESTRITO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(PONTUACAOPROFISSIONAL AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(COMISSAOPROFISSIONAL AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LIBSEMENDERECOCOBRANCA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LIBALTERACAOPRECOUNITARIO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LIBVALORCHEQUEACIMAPERMITIDO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(VALORDESCONTOMAXIMOFORMAPAGTO AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LIBPARCELAMINIMA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',  [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(OIDSERIALECF AS CHAR(254)))),0) +'**],'''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(INTEGRASAGA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LIBEMISSAOBOLETO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(DAVCANCELADO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(IMPRIMIUNFMANUAL AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LIBULTIMASENHA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(TIPORECEBIMENTO AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LIBALTVALSERVICO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(BLOQUEIADESDOBRAMENTO AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LIBALTERAPRECOOFERTA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(DESCONTOPORPERCENTUAL AS CHAR(254)))),0) +'
     '+ ')', 'PEDICLICOMPLEMENTO' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'PEDICLICOMPLEMENTO_U' AND type = 'TR')
   drop trigger PEDICLICOMPLEMENTO_U
go
create trigger dbo.PEDICLICOMPLEMENTO_U on dbo.PEDICLICOMPLEMENTO for update as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )    SELECT getdate(), null,'UPDATE PEDICLICOMPLEMENTO SET     AGREGAFRETE = '+ ISNULL(LTRIM(RTRIM(CAST(AGREGAFRETE AS CHAR(254)))),0) +',    CODIGOREGIAO = '+ ISNULL(LTRIM(RTRIM(CAST(CODIGOREGIAO AS CHAR(254)))),0) +',    CONSIGNACAO = '+ ISNULL(LTRIM(RTRIM(CAST(CONSIGNACAO AS CHAR(254)))),0) +',    DESCONTOITENS = '+ ISNULL(LTRIM(RTRIM(CAST(DESCONTOITENS AS CHAR(254)))),0) +',    DESCONTOMOEDA2 = '+ ISNULL(LTRIM(RTRIM(CAST(DESCONTOMOEDA2 AS CHAR(254)))),0) +',    DESCTOINFORMADOFORMADEPAGAR = '+ ISNULL(LTRIM(RTRIM(CAST(DESCTOINFORMADOFORMADEPAGAR AS CHAR(254)))),0) +',    DESCTOINFORMADOTIPOFRETE = '+ ISNULL(LTRIM(RTRIM(CAST(DESCTOINFORMADOTIPOFRETE AS CHAR(254)))),0) +',    DESCTOINFORMADOTOTALPEDIDO = '+ ISNULL(LTRIM(RTRIM(CAST(DESCTOINFORMADOTOTALPEDIDO AS CHAR(254)))),0) +',    FRETEORCMOEDA2 = '+ ISNULL(LTRIM(RTRIM(CAST(FRETEORCMOEDA2 AS CHAR(254)))),0) +',    FRETEPAGAR = '+ ISNULL(LTRIM(RTRIM(CAST(FRETEPAGAR AS CHAR(254)))),0) +',    KMATUAL = '+ ISNULL(LTRIM(RTRIM(CAST(KMATUAL AS CHAR(254)))),0) +',    KMMES = '+ ISNULL(LTRIM(RTRIM(CAST(KMMES AS CHAR(254)))),0) +',    MOEDA = '+ ISNULL(LTRIM(RTRIM(CAST(MOEDA AS CHAR(254)))),0) +',    MOTIVOCANCELAMENTO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(MOTIVOCANCELAMENTO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    OBSERVACAOCREDIARIO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(OBSERVACAOCREDIARIO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    OIDCONTRATANTE = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(OIDCONTRATANTE AS CHAR(254)))),0) +'**],    PLACA = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(PLACA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    SEMCONSOLIDACAO = '+ ISNULL(LTRIM(RTRIM(CAST(SEMCONSOLIDACAO AS CHAR(254)))),0) +',    TABELAPRECOAUXILIAR = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(TABELAPRECOAUXILIAR AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    TIPOUSUARIO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(TIPOUSUARIO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    VALPEDMOEDA2 = '+ ISNULL(LTRIM(RTRIM(CAST(VALPEDMOEDA2 AS CHAR(254)))),0) +',    VALSEGUROMOEDA2 = '+ ISNULL(LTRIM(RTRIM(CAST(VALSEGUROMOEDA2 AS CHAR(254)))),0) +',    LIBORCOUTRVEN = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LIBORCOUTRVEN AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    MARKUPREALTOTAL = '+ ISNULL(LTRIM(RTRIM(CAST(MARKUPREALTOTAL AS CHAR(254)))),0) +',    RSEGURO = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(RSEGURO AS CHAR(254)))),0) +'**],    ENTREGAPOSTERIOR = '+ ISNULL(LTRIM(RTRIM(CAST(ENTREGAPOSTERIOR AS CHAR(254)))),0) +',    LIBENTREGAPOSTERIOR = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LIBENTREGAPOSTERIOR AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    DIFERENCAPEDIDOEXTERNO = '+ ISNULL(LTRIM(RTRIM(CAST(DIFERENCAPEDIDOEXTERNO AS CHAR(254)))),0) +',    VENDAESPECIAL = '+ ISNULL(LTRIM(RTRIM(CAST(VENDAESPECIAL AS CHAR(254)))),0) +',    FORMAPAGAMENTOCOMISSAO = '+ ISNULL(LTRIM(RTRIM(CAST(FORMAPAGAMENTOCOMISSAO AS CHAR(254)))),0) +',    TIPODOCUMENTOCOMISSAO = '+ ISNULL(LTRIM(RTRIM(CAST(TIPODOCUMENTOCOMISSAO AS CHAR(254)))),0) +',    DATAMARCADA = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DATAMARCADA,20)))+''',120)','NULL')+',    TURNO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(TURNO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    RBAIRRO = '+ ISNULL(LTRIM(RTRIM(CAST(RBAIRRO AS CHAR(254)))),0) +',    CLASSE = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CLASSE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    VALCUSTOFRETE = '+ ISNULL(LTRIM(RTRIM(CAST(VALCUSTOFRETE AS CHAR(254)))),0) +',    TEF_ATIVO = '+ ISNULL(LTRIM(RTRIM(CAST(TEF_ATIVO AS CHAR(254)))),0) +',    LIBDESCPAGTOCLIENTE = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LIBDESCPAGTOCLIENTE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    MEIODEDIVULGACAO = '+ ISNULL(LTRIM(RTRIM(CAST(MEIODEDIVULGACAO AS CHAR(254)))),0) +',    PERCDESCADICIONALPRODEMOFERTA = '+ ISNULL(LTRIM(RTRIM(CAST(PERCDESCADICIONALPRODEMOFERTA AS CHAR(254)))),0) +',    PERCDESCADICIONALPRODSEMOFERTA = '+ ISNULL(LTRIM(RTRIM(CAST(PERCDESCADICIONALPRODSEMOFERTA AS CHAR(254)))),0) +',    COPIAPEDIDO = '+ ISNULL(LTRIM(RTRIM(CAST(COPIAPEDIDO AS CHAR(254)))),0) +',    DTPREVISAOFATURAMENTO = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DTPREVISAOFATURAMENTO,20)))+''',120)','NULL')+',    REFERENCIAENDERECO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(REFERENCIAENDERECO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    DTPRIMEIRAPARCELA = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DTPRIMEIRAPARCELA,20)))+''',120)','NULL')+',    OBSERVACAONF = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(OBSERVACAONF AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    OBSNFTEXTOLIVRE = '+ ISNULL(LTRIM(RTRIM(CAST(OBSNFTEXTOLIVRE AS CHAR(254)))),0) +',    LIBTRANSPORTADORA = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LIBTRANSPORTADORA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    LIBPARCELAMINIMACARTAO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LIBPARCELAMINIMACARTAO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    OIDPESSOAAUTORIZADA = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(OIDPESSOAAUTORIZADA AS CHAR(254)))),0) +'**],    LIBPESSOAAUTORIZADA = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LIBPESSOAAUTORIZADA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    NUMPEDGERADO = '+ ISNULL(LTRIM(RTRIM(CAST(NUMPEDGERADO AS CHAR(254)))),0) +',    LIBPESODIVERGENTE = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LIBPESODIVERGENTE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    NUMDAV = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NUMDAV AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    LIBORCTOESPECIAL = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LIBORCTOESPECIAL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    SIMPLESFATURAMENTO = '+ ISNULL(LTRIM(RTRIM(CAST(SIMPLESFATURAMENTO AS CHAR(254)))),0) +',    LIBTABPRECO = '+ ISNULL(LTRIM(RTRIM(CAST(LIBTABPRECO AS CHAR(254)))),0) +',    MANTERRESERVA = '+ ISNULL(LTRIM(RTRIM(CAST(MANTERRESERVA AS CHAR(254)))),0) +',    LIBMANTERRESERVA = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LIBMANTERRESERVA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    RSESSAODEUSO = '+ ISNULL(LTRIM(RTRIM(CAST(RSESSAODEUSO AS CHAR(254)))),0) +',    NUMEROCUPOM = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NUMEROCUPOM AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    VALORICMSDISPENSADO = '+ ISNULL(LTRIM(RTRIM(CAST(VALORICMSDISPENSADO AS CHAR(254)))),0) +',    FILIALESTOQUE = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(FILIALESTOQUE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    LIBORCTORECANTECIPADO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LIBORCTORECANTECIPADO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    DTLIBORCRECANTECIPADO = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DTLIBORCRECANTECIPADO,20)))+''',120)','NULL')+',    NUMPEDTRANSF = '+ ISNULL(LTRIM(RTRIM(CAST(NUMPEDTRANSF AS CHAR(254)))),0) +',    LIBPRECOMINIMO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LIBPRECOMINIMO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    LIBAUTELETRONICA = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LIBAUTELETRONICA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    TOKENCELREF = '+ ISNULL(LTRIM(RTRIM(CAST(TOKENCELREF AS CHAR(254)))),0) +',    ULTCODSENCEL = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ULTCODSENCEL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    NUMEROLISTA = '+ ISNULL(LTRIM(RTRIM(CAST(NUMEROLISTA AS CHAR(254)))),0) +',    ENTREGAEXPRESSA = '+ ISNULL(LTRIM(RTRIM(CAST(ENTREGAEXPRESSA AS CHAR(254)))),0) +',    PERCFRETE = '+ ISNULL(LTRIM(RTRIM(CAST(PERCFRETE AS CHAR(254)))),0) +',    LIBRESERVA = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LIBRESERVA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    LIBCHEQUE = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LIBCHEQUE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    LIBRECENTREGA = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LIBRECENTREGA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    LIBFRETEINFERIOR = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LIBFRETEINFERIOR AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    LIBRECEBENAENTREGA = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LIBRECEBENAENTREGA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    LIBTIPOTRANSPORTE = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LIBTIPOTRANSPORTE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CODENDSEG = '+ ISNULL(LTRIM(RTRIM(CAST(CODENDSEG AS CHAR(254)))),0) +',    CLIENTESOLIDARIO = '+ ISNULL(LTRIM(RTRIM(CAST(CLIENTESOLIDARIO AS CHAR(254)))),0) +',    DESCONTOSUFRAMA = '+ ISNULL(LTRIM(RTRIM(CAST(DESCONTOSUFRAMA AS CHAR(254)))),0) +',    EMAIL = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(EMAIL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    ALTERACAO = '+ ISNULL(LTRIM(RTRIM(CAST(ALTERACAO AS CHAR(254)))),0) +',    IMPRESSAO = '+ ISNULL(LTRIM(RTRIM(CAST(IMPRESSAO AS CHAR(254)))),0) +',    VALDESCONTOFRETE = '+ ISNULL(LTRIM(RTRIM(CAST(VALDESCONTOFRETE AS CHAR(254)))),0) +',    LIBLOTERESERVADO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LIBLOTERESERVADO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    LIBCLIVEN = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LIBCLIVEN AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    LIBVENFUTDOCDEV = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LIBVENFUTDOCDEV AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    LIBFILIALPREFERENCIAL = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LIBFILIALPREFERENCIAL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    RECALCULARVENCIMENTO = '+ ISNULL(LTRIM(RTRIM(CAST(RECALCULARVENCIMENTO AS CHAR(254)))),0) +',    MERCADORIAREVENDA = '+ ISNULL(LTRIM(RTRIM(CAST(MERCADORIAREVENDA AS CHAR(254)))),0) +',    OBSPENDENCIA = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(OBSPENDENCIA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    PENDENCIADOCUMENTOS = '+ ISNULL(LTRIM(RTRIM(CAST(PENDENCIADOCUMENTOS AS CHAR(254)))),0) +',    RSEPARADOR = '+ ISNULL(LTRIM(RTRIM(CAST(RSEPARADOR AS CHAR(254)))),0) +',    RCONFERENTE = '+ ISNULL(LTRIM(RTRIM(CAST(RCONFERENTE AS CHAR(254)))),0) +',    LIBBLOQUEIOPRODTRANSP = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LIBBLOQUEIOPRODTRANSP AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    VENDAPARACAEMG = '+ ISNULL(LTRIM(RTRIM(CAST(VENDAPARACAEMG AS CHAR(254)))),0) +',    ACRESCIMOFINANCEIRO = '+ ISNULL(LTRIM(RTRIM(CAST(ACRESCIMOFINANCEIRO AS CHAR(254)))),0) +',    TAXAACRESCIMOFINANCEIRO = '+ ISNULL(LTRIM(RTRIM(CAST(TAXAACRESCIMOFINANCEIRO AS CHAR(254)))),0) +',    SENHAALTERARACRESCIMO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(SENHAALTERARACRESCIMO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    ENDERECOFAT = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ENDERECOFAT AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    BAIRROFAT = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(BAIRROFAT AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    COMPLEMENTOFAT = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(COMPLEMENTOFAT AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    NUMEROFAT = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NUMEROFAT AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CEPFAT = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CEPFAT AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CIDADEFAT = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CIDADEFAT AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    ESTADOFAT = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ESTADOFAT AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    REFERENCIAFAT = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(REFERENCIAFAT AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    EXPORTADO = '+ ISNULL(LTRIM(RTRIM(CAST(EXPORTADO AS CHAR(254)))),0) +',    LIBALTERACAODEPOSITOINTERNO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LIBALTERACAODEPOSITOINTERNO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    OIDSEGMENTO = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(OIDSEGMENTO AS CHAR(254)))),0) +'**],    AREADEVENDAS = '+ ISNULL(LTRIM(RTRIM(CAST(AREADEVENDAS AS CHAR(254)))),0) +',    USULIBPENDPLANOBASE = '+ ISNULL(LTRIM(RTRIM(CAST(USULIBPENDPLANOBASE AS CHAR(254)))),0) +',    VENDEDORDESDOBRAMENTO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(VENDEDORDESDOBRAMENTO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    DESCONTOIMPORTADOS = '+ ISNULL(LTRIM(RTRIM(CAST(DESCONTOIMPORTADOS AS CHAR(254)))),0) +',    PERCDESCONTOIMPORTADOS = '+ ISNULL(LTRIM(RTRIM(CAST(PERCDESCONTOIMPORTADOS AS CHAR(254)))),0) +',    CCFDAV = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CCFDAV AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    SERIALECFDAV = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(SERIALECFDAV AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    COODAV = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(COODAV AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    DTEMISDAV = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DTEMISDAV,20)))+''',120)','NULL')+',    VALORDESCONTOPISCOFINS = '+ ISNULL(LTRIM(RTRIM(CAST(VALORDESCONTOPISCOFINS AS CHAR(254)))),0) +',    CODENDFAT = '+ ISNULL(LTRIM(RTRIM(CAST(CODENDFAT AS CHAR(254)))),0) +',    NUMPEDIMPORTADO = '+ ISNULL(LTRIM(RTRIM(CAST(NUMPEDIMPORTADO AS CHAR(254)))),0) +',    FINALIDADE = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(FINALIDADE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CODVENDINTERNO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODVENDINTERNO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    LIBDESCTOITEMOFERTA = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LIBDESCTOITEMOFERTA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    LIBFATTIPODOCRESTRITO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LIBFATTIPODOCRESTRITO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    PONTUACAOPROFISSIONAL = '+ ISNULL(LTRIM(RTRIM(CAST(PONTUACAOPROFISSIONAL AS CHAR(254)))),0) +',    COMISSAOPROFISSIONAL = '+ ISNULL(LTRIM(RTRIM(CAST(COMISSAOPROFISSIONAL AS CHAR(254)))),0) +',    LIBSEMENDERECOCOBRANCA = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LIBSEMENDERECOCOBRANCA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    LIBALTERACAOPRECOUNITARIO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LIBALTERACAOPRECOUNITARIO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    LIBVALORCHEQUEACIMAPERMITIDO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LIBVALORCHEQUEACIMAPERMITIDO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    VALORDESCONTOMAXIMOFORMAPAGTO = '+ ISNULL(LTRIM(RTRIM(CAST(VALORDESCONTOMAXIMOFORMAPAGTO AS CHAR(254)))),0) +',    LIBPARCELAMINIMA = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LIBPARCELAMINIMA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    OIDSERIALECF = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(OIDSERIALECF AS CHAR(254)))),0) +'**],    INTEGRASAGA = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(INTEGRASAGA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    LIBEMISSAOBOLETO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LIBEMISSAOBOLETO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    DAVCANCELADO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(DAVCANCELADO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    IMPRIMIUNFMANUAL = '+ ISNULL(LTRIM(RTRIM(CAST(IMPRIMIUNFMANUAL AS CHAR(254)))),0) +',    LIBULTIMASENHA = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LIBULTIMASENHA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    TIPORECEBIMENTO = '+ ISNULL(LTRIM(RTRIM(CAST(TIPORECEBIMENTO AS CHAR(254)))),0) +',    LIBALTVALSERVICO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LIBALTVALSERVICO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    BLOQUEIADESDOBRAMENTO = '+ ISNULL(LTRIM(RTRIM(CAST(BLOQUEIADESDOBRAMENTO AS CHAR(254)))),0) +',    LIBALTERAPRECOOFERTA = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LIBALTERAPRECOOFERTA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    DESCONTOPORPERCENTUAL = '+ ISNULL(LTRIM(RTRIM(CAST(DESCONTOPORPERCENTUAL AS CHAR(254)))),0) +''+  ' WHERE NUMPED = '+ RTRIM(CAST(NUMPED as char(254))) +  ''   , 'PEDICLICOMPLEMENTO' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'PEDICLIDESPESA_D' AND type = 'TR')
  drop trigger PEDICLIDESPESA_D
go
create trigger dbo.PEDICLIDESPESA_D on dbo.PEDICLIDESPESA for delete as
    Begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
            SELECT getdate(), null,'DELETE FROM PEDICLIDESPESA WHERE 
NUMPED = '+ RTRIM(LTRIM(CAST(NUMPED as char(120)))) + '  and OIDDESPESA = '+ RTRIM(LTRIM(CAST(OIDDESPESA as char(120)))) + ' ','PEDICLIDESPESA' from deleted
    End
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'PEDICLIDESPESA_I' AND type = 'TR')
   drop trigger PEDICLIDESPESA_I
go
create trigger dbo.PEDICLIDESPESA_I on dbo.PEDICLIDESPESA for insert as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
    SELECT getdate(), null,'INSERT INTO PEDICLIDESPESA(
        NUMPED,    OIDDESPESA,    RFORNECEDOR,    VALOR)
    VALUES (
    '+ ISNULL(LTRIM(RTRIM(CAST(NUMPED AS CHAR(254)))),0) +',  [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(OIDDESPESA AS CHAR(254)))),0) +'**],'+ ISNULL(LTRIM(RTRIM(CAST(RFORNECEDOR AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALOR AS CHAR(254)))),0) +'
     '+ ')', 'PEDICLIDESPESA' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'PEDICLIDESPESA_U' AND type = 'TR')
   drop trigger PEDICLIDESPESA_U
go
create trigger dbo.PEDICLIDESPESA_U on dbo.PEDICLIDESPESA for update as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )    SELECT getdate(), null,'UPDATE PEDICLIDESPESA SET     RFORNECEDOR = '+ ISNULL(LTRIM(RTRIM(CAST(RFORNECEDOR AS CHAR(254)))),0) +',    VALOR = '+ ISNULL(LTRIM(RTRIM(CAST(VALOR AS CHAR(254)))),0) +''+  ' WHERE NUMPED = '+ RTRIM(CAST(NUMPED as char(254))) +  ' and     OIDDESPESA = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(OIDDESPESA AS CHAR(254)))),0) +'**]'  , 'PEDICLIDESPESA' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'PEDICLIEMPENHO_D' AND type = 'TR')
  drop trigger PEDICLIEMPENHO_D
go
create trigger dbo.PEDICLIEMPENHO_D on dbo.PEDICLIEMPENHO for delete as
    Begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
            SELECT getdate(), null,'DELETE FROM PEDICLIEMPENHO WHERE 
NUMPED = '+ RTRIM(LTRIM(CAST(NUMPED as char(120)))) + ' ','PEDICLIEMPENHO' from deleted
    End
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'PEDICLIEMPENHO_I' AND type = 'TR')
   drop trigger PEDICLIEMPENHO_I
go
create trigger dbo.PEDICLIEMPENHO_I on dbo.PEDICLIEMPENHO for insert as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
    SELECT getdate(), null,'INSERT INTO PEDICLIEMPENHO(
        NUMPED,    TIPOORCAMENTO,    NUMERO,    PROCESSO,    ABERTURA,    ENCERRAMENTO)
    VALUES (
    '+ ISNULL(LTRIM(RTRIM(CAST(NUMPED AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(TIPOORCAMENTO AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NUMERO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(PROCESSO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,ABERTURA,20 ))) +''',120)','NULL')+','+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,ENCERRAMENTO,20 ))) +''',120)','NULL')+'
     '+ ')', 'PEDICLIEMPENHO' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'PEDICLIEMPENHO_U' AND type = 'TR')
   drop trigger PEDICLIEMPENHO_U
go
create trigger dbo.PEDICLIEMPENHO_U on dbo.PEDICLIEMPENHO for update as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )    SELECT getdate(), null,'UPDATE PEDICLIEMPENHO SET     TIPOORCAMENTO = '+ ISNULL(LTRIM(RTRIM(CAST(TIPOORCAMENTO AS CHAR(254)))),0) +',    NUMERO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NUMERO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    PROCESSO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(PROCESSO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    ABERTURA = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,ABERTURA,20)))+''',120)','NULL')+',    ENCERRAMENTO = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,ENCERRAMENTO,20)))+''',120)','NULL')+  ' WHERE NUMPED = '+ RTRIM(CAST(NUMPED as char(254))) +  ''   , 'PEDICLIEMPENHO' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'PEDICLILIBERAR_D' AND type = 'TR')
  drop trigger PEDICLILIBERAR_D
go
create trigger dbo.PEDICLILIBERAR_D on dbo.PEDICLILIBERAR for delete as
    Begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
            SELECT getdate(), null,'DELETE FROM PEDICLILIBERAR WHERE 
NUMPED = '+ RTRIM(LTRIM(CAST(NUMPED as char(120)))) + ' ','PEDICLILIBERAR' from deleted
    End
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'PEDICLILIBERAR_I' AND type = 'TR')
   drop trigger PEDICLILIBERAR_I
go
create trigger dbo.PEDICLILIBERAR_I on dbo.PEDICLILIBERAR for insert as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
    SELECT getdate(), null,'INSERT INTO PEDICLILIBERAR(
        FILIAL,    NUMPED,    DTPEDIDO,    CODCLIE,    NOME,    VALPED,    CODVEND,    ENTREGAEXPRESSA)
    VALUES (
    '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(FILIAL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(NUMPED AS CHAR(254)))),0) +','+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DTPEDIDO,20 ))) +''',120)','NULL')+',  [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(CODCLIE AS CHAR(254)))),0) +'**],'''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NOME AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(VALPED AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODVEND AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(ENTREGAEXPRESSA AS CHAR(254)))),0) +'
     '+ ')', 'PEDICLILIBERAR' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'PEDICLILIBERAR_U' AND type = 'TR')
   drop trigger PEDICLILIBERAR_U
go
create trigger dbo.PEDICLILIBERAR_U on dbo.PEDICLILIBERAR for update as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )    SELECT getdate(), null,'UPDATE PEDICLILIBERAR SET     FILIAL = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(FILIAL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    DTPEDIDO = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DTPEDIDO,20)))+''',120)','NULL')+',    CODCLIE = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(CODCLIE AS CHAR(254)))),0) +'**],    NOME = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NOME AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    VALPED = '+ ISNULL(LTRIM(RTRIM(CAST(VALPED AS CHAR(254)))),0) +',    CODVEND = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODVEND AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    ENTREGAEXPRESSA = '+ ISNULL(LTRIM(RTRIM(CAST(ENTREGAEXPRESSA AS CHAR(254)))),0) +''+  ' WHERE NUMPED = '+ RTRIM(CAST(NUMPED as char(254))) +  ''   , 'PEDICLILIBERAR' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'PEDICLITEXTO_D' AND type = 'TR')
  drop trigger PEDICLITEXTO_D
go
create trigger dbo.PEDICLITEXTO_D on dbo.PEDICLITEXTO for delete as
    Begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
            SELECT getdate(), null,'DELETE FROM PEDICLITEXTO WHERE 
NUMPED = '+ RTRIM(LTRIM(CAST(NUMPED as char(120)))) + '  and ORDEM = '+ RTRIM(LTRIM(CAST(ORDEM as char(120)))) + ' ','PEDICLITEXTO' from deleted
    End
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'PEDICLITEXTO_I' AND type = 'TR')
   drop trigger PEDICLITEXTO_I
go
create trigger dbo.PEDICLITEXTO_I on dbo.PEDICLITEXTO for insert as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
    SELECT getdate(), null,'INSERT INTO PEDICLITEXTO(
        NUMPED,    ORDEM,    RTEXTO)
    VALUES (
    '+ ISNULL(LTRIM(RTRIM(CAST(NUMPED AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ORDEM AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(RTEXTO AS CHAR(254)))),0) +'
     '+ ')', 'PEDICLITEXTO' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'PEDICLITEXTO_U' AND type = 'TR')
   drop trigger PEDICLITEXTO_U
go
create trigger dbo.PEDICLITEXTO_U on dbo.PEDICLITEXTO for update as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )    SELECT getdate(), null,'UPDATE PEDICLITEXTO SET     RTEXTO = '+ ISNULL(LTRIM(RTRIM(CAST(RTEXTO AS CHAR(254)))),0) +''+  ' WHERE NUMPED = '+ RTRIM(CAST(NUMPED as char(254))) +  ' and ORDEM = '+ RTRIM(CAST(ORDEM as char(254))) +  ''   , 'PEDICLITEXTO' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'PEDIDOCANCELADO_D' AND type = 'TR')
  drop trigger PEDIDOCANCELADO_D
go
create trigger dbo.PEDIDOCANCELADO_D on dbo.PEDIDOCANCELADO for delete as
    Begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
            SELECT getdate(), null,'DELETE FROM PEDIDOCANCELADO WHERE 
IDENTIFICADOR = '+ RTRIM(LTRIM(CAST(IDENTIFICADOR as char(120)))) + ' ','PEDIDOCANCELADO' from deleted
    End
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'PEDIDOCANCELADO_INST_I' AND type = 'TR')
   drop trigger PEDIDOCANCELADO_INST_I
go
create trigger dbo.PEDIDOCANCELADO_INST_I on dbo.PEDIDOCANCELADO INSTEAD OF insert as
begin
    SELECT * INTO #Inserted FROM Inserted
    UPDATE #Inserted SET IDENTIFICADOR = (@@spid*-1)
    INSERT INTO PEDIDOCANCELADO SELECT * FROM #Inserted
    Return
end
go
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'PEDIDOCANCELADO_I' AND type = 'TR')
   drop trigger PEDIDOCANCELADO_I
go
create trigger dbo.PEDIDOCANCELADO_I on dbo.PEDIDOCANCELADO for insert as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
    SELECT getdate(), null,'INSERT INTO PEDIDOCANCELADO(
        USUARIO,    NUMORD,    SITFINANCEIRA,    SITFISCAL,    SITCOMISSAO,    OBSFINANCEIRA,    OBSFISCAL,    DTSITFINANCEIRA,    DTSITFISCAL,    DTSITCOMISSAO,    IDENTIFICADOR,    CODVEND,    NUMPED,    FILIAL,    NUMPEDAVULSO,    DATA,    MOTIVO,    DATALIBERACAO,    DATARECEBIMENTO,    TAXACANCELAMENTO)
    VALUES (
      [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(USUARIO AS CHAR(254)))),0) +'**],'+ ISNULL(LTRIM(RTRIM(CAST(NUMORD AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(SITFINANCEIRA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(SITFISCAL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(SITCOMISSAO AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(OBSFINANCEIRA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(OBSFISCAL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DTSITFINANCEIRA,20 ))) +''',120)','NULL')+','+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DTSITFISCAL,20 ))) +''',120)','NULL')+','+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DTSITCOMISSAO,20 ))) +''',120)','NULL')+','+ ISNULL(LTRIM(RTRIM(CAST(IDENTIFICADOR AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODVEND AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(NUMPED AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(FILIAL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(NUMPEDAVULSO AS CHAR(254)))),0) +','+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DATA,20 ))) +''',120)','NULL')+','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(MOTIVO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DATALIBERACAO,20 ))) +''',120)','NULL')+','+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DATARECEBIMENTO,20 ))) +''',120)','NULL')+','+ ISNULL(LTRIM(RTRIM(CAST(TAXACANCELAMENTO AS CHAR(254)))),0) +'
     '+ ')', 'PEDIDOCANCELADO' FROM inserted
    declare @nContador integer
    exec GERASEMENTE_P 'TW_IDENTIFICADOR', 7, @nContador OUTPUT
    if @nContador > 0
      update PEDIDOCANCELADO set IDENTIFICADOR = @nContador WHERE IDENTIFICADOR = (select IDENTIFICADOR from inserted WHERE IDENTIFICADOR=(@@spid*-1))
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'PEDIDOCANCELADO_U' AND type = 'TR')
   drop trigger PEDIDOCANCELADO_U
go
create trigger dbo.PEDIDOCANCELADO_U on dbo.PEDIDOCANCELADO for update as
begin
  if (select count(*) from deleted where IDENTIFICADOR = @@spid*-1 ) > 0
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )    SELECT getdate(), null,'UPDATE PEDIDOCANCELADO SET     USUARIO = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(USUARIO AS CHAR(254)))),0) +'**],    NUMORD = '+ ISNULL(LTRIM(RTRIM(CAST(NUMORD AS CHAR(254)))),0) +',    SITFINANCEIRA = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(SITFINANCEIRA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    SITFISCAL = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(SITFISCAL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    SITCOMISSAO = '+ ISNULL(LTRIM(RTRIM(CAST(SITCOMISSAO AS CHAR(254)))),0) +',    OBSFINANCEIRA = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(OBSFINANCEIRA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    OBSFISCAL = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(OBSFISCAL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    DTSITFINANCEIRA = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DTSITFINANCEIRA,20)))+''',120)','NULL')+',    DTSITFISCAL = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DTSITFISCAL,20)))+''',120)','NULL')+',    DTSITCOMISSAO = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DTSITCOMISSAO,20)))+''',120)','NULL')+',    IDENTIFICADOR = '+ ISNULL(LTRIM(RTRIM(CAST(IDENTIFICADOR AS CHAR(254)))),0) +',    CODVEND = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODVEND AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    NUMPED = '+ ISNULL(LTRIM(RTRIM(CAST(NUMPED AS CHAR(254)))),0) +',    FILIAL = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(FILIAL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    NUMPEDAVULSO = '+ ISNULL(LTRIM(RTRIM(CAST(NUMPEDAVULSO AS CHAR(254)))),0) +',    DATA = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DATA,20)))+''',120)','NULL')+',    MOTIVO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(MOTIVO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    DATALIBERACAO = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DATALIBERACAO,20)))+''',120)','NULL')+',    DATARECEBIMENTO = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DATARECEBIMENTO,20)))+''',120)','NULL')+',    TAXACANCELAMENTO = '+ ISNULL(LTRIM(RTRIM(CAST(TAXACANCELAMENTO AS CHAR(254)))),0) +''+  ' WHERE IDENTIFICADOR = '+ ISNULL(LTRIM(RTRIM(CAST((@@spid*-1) AS CHAR(254)))),0) , 'PEDIDOCANCELADO' FROM inserted
 else
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )    SELECT getdate(), null,'UPDATE PEDIDOCANCELADO SET     USUARIO = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(USUARIO AS CHAR(254)))),0) +'**],    NUMORD = '+ ISNULL(LTRIM(RTRIM(CAST(NUMORD AS CHAR(254)))),0) +',    SITFINANCEIRA = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(SITFINANCEIRA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    SITFISCAL = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(SITFISCAL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    SITCOMISSAO = '+ ISNULL(LTRIM(RTRIM(CAST(SITCOMISSAO AS CHAR(254)))),0) +',    OBSFINANCEIRA = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(OBSFINANCEIRA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    OBSFISCAL = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(OBSFISCAL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    DTSITFINANCEIRA = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DTSITFINANCEIRA,20)))+''',120)','NULL')+',    DTSITFISCAL = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DTSITFISCAL,20)))+''',120)','NULL')+',    DTSITCOMISSAO = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DTSITCOMISSAO,20)))+''',120)','NULL')+',    IDENTIFICADOR = '+ ISNULL(LTRIM(RTRIM(CAST(IDENTIFICADOR AS CHAR(254)))),0) +',    CODVEND = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODVEND AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    NUMPED = '+ ISNULL(LTRIM(RTRIM(CAST(NUMPED AS CHAR(254)))),0) +',    FILIAL = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(FILIAL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    NUMPEDAVULSO = '+ ISNULL(LTRIM(RTRIM(CAST(NUMPEDAVULSO AS CHAR(254)))),0) +',    DATA = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DATA,20)))+''',120)','NULL')+',    MOTIVO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(MOTIVO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    DATALIBERACAO = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DATALIBERACAO,20)))+''',120)','NULL')+',    DATARECEBIMENTO = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DATARECEBIMENTO,20)))+''',120)','NULL')+',    TAXACANCELAMENTO = '+ ISNULL(LTRIM(RTRIM(CAST(TAXACANCELAMENTO AS CHAR(254)))),0) +''+  ' WHERE IDENTIFICADOR = '+ RTRIM(CAST(IDENTIFICADOR as char(254))) +  ''   , 'PEDIDOCANCELADO' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'PERDVENCAD_D' AND type = 'TR')
  drop trigger PERDVENCAD_D
go
create trigger dbo.PERDVENCAD_D on dbo.PERDVENCAD for delete as
    Begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
            SELECT getdate(), null,'DELETE FROM PERDVENCAD WHERE 
filial = '''+ RTRIM(LTRIM(filial)) + '''  and numped = '+ RTRIM(LTRIM(CAST(numped as char(120)))) + '  and codclie = '+ RTRIM(LTRIM(CAST(codclie as char(120)))) + '  and codpro = '''+ RTRIM(LTRIM(codpro)) + ''' ','PERDVENCAD' from deleted
    End
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'PERDVENCAD_I' AND type = 'TR')
   drop trigger PERDVENCAD_I
go
create trigger dbo.PERDVENCAD_I on dbo.PERDVENCAD for insert as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
    SELECT getdate(), null,'INSERT INTO PERDVENCAD(
        CODCLIE,    CODPRO,    DATAMOV,    QUANT,    MOTIVO,    CONCOR,    PRECCOR,    PRECOVEN,    MOEPRECO,    OBSERV,    CODVEND,    ICMSNEGPRE,    FILIAL,    NUMPED)
    VALUES (
      [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(CODCLIE AS CHAR(254)))),0) +'**],'''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODPRO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DATAMOV,20 ))) +''',120)','NULL')+','+ ISNULL(LTRIM(RTRIM(CAST(QUANT AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(MOTIVO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CONCOR AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(PRECCOR AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(PRECOVEN AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(MOEPRECO AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(OBSERV AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODVEND AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(ICMSNEGPRE AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(FILIAL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(NUMPED AS CHAR(254)))),0) +'
     '+ ')', 'PERDVENCAD' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'PERDVENCAD_U' AND type = 'TR')
   drop trigger PERDVENCAD_U
go
create trigger dbo.PERDVENCAD_U on dbo.PERDVENCAD for update as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )    SELECT getdate(), null,'UPDATE PERDVENCAD SET     DATAMOV = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DATAMOV,20)))+''',120)','NULL')+',    QUANT = '+ ISNULL(LTRIM(RTRIM(CAST(QUANT AS CHAR(254)))),0) +',    MOTIVO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(MOTIVO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CONCOR = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CONCOR AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    PRECCOR = '+ ISNULL(LTRIM(RTRIM(CAST(PRECCOR AS CHAR(254)))),0) +',    PRECOVEN = '+ ISNULL(LTRIM(RTRIM(CAST(PRECOVEN AS CHAR(254)))),0) +',    MOEPRECO = '+ ISNULL(LTRIM(RTRIM(CAST(MOEPRECO AS CHAR(254)))),0) +',    OBSERV = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(OBSERV AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CODVEND = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODVEND AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    ICMSNEGPRE = '+ ISNULL(LTRIM(RTRIM(CAST(ICMSNEGPRE AS CHAR(254)))),0) +''+  ' WHERE filial = '''+ RTRIM(filial)  + ''' and numped = '+ RTRIM(CAST(numped as char(254))) +  ' and     codclie = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(codclie AS CHAR(254)))),0) +'**] and codpro = '''+ RTRIM(codpro)  + ''''   , 'PERDVENCAD' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'PRECUPOM_D' AND type = 'TR')
  drop trigger PRECUPOM_D
go
create trigger dbo.PRECUPOM_D on dbo.PRECUPOM for delete as
    Begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
            SELECT getdate(), null,'DELETE FROM PRECUPOM WHERE 
OID = '+ RTRIM(LTRIM(CAST(OID as char(120)))) + ' ','PRECUPOM' from deleted
    End
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'PRECUPOM_I' AND type = 'TR')
   drop trigger PRECUPOM_I
go
create trigger dbo.PRECUPOM_I on dbo.PRECUPOM for insert as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
    SELECT getdate(), null,'INSERT INTO PRECUPOM(
        FILIAL,    DATA,    SERIALECF,    OIDSERIALECF,    COO,    CCF,    ITEM,    CODPRO,    UNIDADE,    QUANTIDADE,    PRECO,    PRECOTABELA,    DESCONTO,    ACRESCIMO,    VALORTOTAL,    CODTOTALIZADOR,    CANCELADO)
    VALUES (
    '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(FILIAL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DATA,20 ))) +''',120)','NULL')+','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(SERIALECF AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(OIDSERIALECF AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(COO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CCF AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(ITEM AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODPRO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(UNIDADE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(QUANTIDADE AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(PRECO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(PRECOTABELA AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(DESCONTO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ACRESCIMO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALORTOTAL AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODTOTALIZADOR AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CANCELADO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +'''
     '+ ')', 'PRECUPOM' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'PRECUPOM_U' AND type = 'TR')
   drop trigger PRECUPOM_U
go
create trigger dbo.PRECUPOM_U on dbo.PRECUPOM for update as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )    SELECT getdate(), null,'UPDATE PRECUPOM SET     FILIAL = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(FILIAL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    DATA = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DATA,20)))+''',120)','NULL')+',    SERIALECF = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(SERIALECF AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    OIDSERIALECF = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(OIDSERIALECF AS CHAR(254)))),0) +'**],    COO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(COO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CCF = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CCF AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    ITEM = '+ ISNULL(LTRIM(RTRIM(CAST(ITEM AS CHAR(254)))),0) +',    CODPRO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODPRO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    UNIDADE = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(UNIDADE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    QUANTIDADE = '+ ISNULL(LTRIM(RTRIM(CAST(QUANTIDADE AS CHAR(254)))),0) +',    PRECO = '+ ISNULL(LTRIM(RTRIM(CAST(PRECO AS CHAR(254)))),0) +',    PRECOTABELA = '+ ISNULL(LTRIM(RTRIM(CAST(PRECOTABELA AS CHAR(254)))),0) +',    DESCONTO = '+ ISNULL(LTRIM(RTRIM(CAST(DESCONTO AS CHAR(254)))),0) +',    ACRESCIMO = '+ ISNULL(LTRIM(RTRIM(CAST(ACRESCIMO AS CHAR(254)))),0) +',    VALORTOTAL = '+ ISNULL(LTRIM(RTRIM(CAST(VALORTOTAL AS CHAR(254)))),0) +',    CODTOTALIZADOR = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODTOTALIZADOR AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CANCELADO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CANCELADO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''''+  ' WHERE     OID = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(OID AS CHAR(254)))),0) +'**]'  , 'PRECUPOM' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'PREVCLICAD_D' AND type = 'TR')
  drop trigger PREVCLICAD_D
go
create trigger dbo.PREVCLICAD_D on dbo.PREVCLICAD for delete as
    Begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
            SELECT getdate(), null,'DELETE FROM PREVCLICAD WHERE 
item = '+ RTRIM(LTRIM(CAST(item as char(120)))) + ' ','PREVCLICAD' from deleted
    End
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'PREVCLICAD_INST_I' AND type = 'TR')
   drop trigger PREVCLICAD_INST_I
go
create trigger dbo.PREVCLICAD_INST_I on dbo.PREVCLICAD INSTEAD OF insert as
begin
    SELECT * INTO #Inserted FROM Inserted
    UPDATE #Inserted SET item = (@@spid*-1)
    INSERT INTO PREVCLICAD SELECT * FROM #Inserted
    Return
end
go
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'PREVCLICAD_I' AND type = 'TR')
   drop trigger PREVCLICAD_I
go
create trigger dbo.PREVCLICAD_I on dbo.PREVCLICAD for insert as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
    SELECT getdate(), null,'INSERT INTO PREVCLICAD(
        NUMPED,    DTPREV,    VALPREV,    TPO,    FILIAL,    NUMORD,    TIPOPAR,    NUMDOC,    COMPLDOC,    LOCALPORTA,    CONTAPORTA,    NUMPARC,    VALPARC,    TIPODOC,    OIDCLIENTE,    ITEM,    OIDPREVFLUXO,    RDOCDEORIGEM,    RECEBIDO,    RCARENCIAPARCELA,    RECDOCENTREGA,    TACEMPRESA,    TACFINANCEIRA,    FATOR1,    FATOR2,    TEMPROMOCAO,    VALREC,    SEGUROEMPRESA,    SEGUROFINANCEIRA,    INFOCHEQUE,    RTIPOAPROVACAO,    GRUPOAPROVACAO,    APROVACAOTRS,    ARQCARNETRS,    DATAESTORNO,    PROPOSTATRS,    STATUSPROPOSTATRS,    VALPREVMOEDA2,    VALPREVTX,    ARQRETTRS,    VALPREVLIQUIDO,    DATAPROPOSTATRS,    FILIALRECEBIMENTO,    CARENCIA,    CODIGOBARRA,    NOMEEMITENTE,    CNPJEMITENTE,    ITEMPAI,    OIDCONTRATOSERVICO,    NUMCONTRATOSERVICO,    TIPOITEM)
    VALUES (
    '+ ISNULL(LTRIM(RTRIM(CAST(NUMPED AS CHAR(254)))),0) +','+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DTPREV,20 ))) +''',120)','NULL')+','+ ISNULL(LTRIM(RTRIM(CAST(VALPREV AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(TPO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(FILIAL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(NUMORD AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(TIPOPAR AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NUMDOC AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(COMPLDOC AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',  [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(LOCALPORTA AS CHAR(254)))),0) +'**],  [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(CONTAPORTA AS CHAR(254)))),0) +'**],'+ ISNULL(LTRIM(RTRIM(CAST(NUMPARC AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALPARC AS CHAR(254)))),0) +',  [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(TIPODOC AS CHAR(254)))),0) +'**],  [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(OIDCLIENTE AS CHAR(254)))),0) +'**],'+ ISNULL(LTRIM(RTRIM(CAST(ITEM AS CHAR(254)))),0) +',  [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(OIDPREVFLUXO AS CHAR(254)))),0) +'**],  [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(RDOCDEORIGEM AS CHAR(254)))),0) +'**],'+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,RECEBIDO,20 ))) +''',120)','NULL')+',  [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(RCARENCIAPARCELA AS CHAR(254)))),0) +'**],'+ ISNULL(LTRIM(RTRIM(CAST(RECDOCENTREGA AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(TACEMPRESA AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(TACFINANCEIRA AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(FATOR1 AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(FATOR2 AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(TEMPROMOCAO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALREC AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(SEGUROEMPRESA AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(SEGUROFINANCEIRA AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(INFOCHEQUE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(RTIPOAPROVACAO AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(GRUPOAPROVACAO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(APROVACAOTRS AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ARQCARNETRS AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DATAESTORNO,20 ))) +''',120)','NULL')+','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(PROPOSTATRS AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(STATUSPROPOSTATRS AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(VALPREVMOEDA2 AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALPREVTX AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ARQRETTRS AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(VALPREVLIQUIDO AS CHAR(254)))),0) +','+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DATAPROPOSTATRS,20 ))) +''',120)','NULL')+','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(FILIALRECEBIMENTO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(CARENCIA AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODIGOBARRA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NOMEEMITENTE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CNPJEMITENTE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(ITEMPAI AS CHAR(254)))),0) +',  [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(OIDCONTRATOSERVICO AS CHAR(254)))),0) +'**],'+ ISNULL(LTRIM(RTRIM(CAST(NUMCONTRATOSERVICO AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(TIPOITEM AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +'''
     '+ ')', 'PREVCLICAD' FROM inserted
    declare @nContador integer
    exec GERASEMENTE_P 'TW_IDENTIFICADOR', 7, @nContador OUTPUT
    if @nContador > 0
      update PREVCLICAD set ITEM = @nContador WHERE ITEM = (select ITEM from inserted WHERE ITEM=(@@spid*-1))
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'PREVCLICAD_U' AND type = 'TR')
   drop trigger PREVCLICAD_U
go
create trigger dbo.PREVCLICAD_U on dbo.PREVCLICAD for update as
begin
  if (select count(*) from deleted where item = @@spid*-1 ) > 0
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )    SELECT getdate(), null,'UPDATE PREVCLICAD SET     NUMPED = '+ ISNULL(LTRIM(RTRIM(CAST(NUMPED AS CHAR(254)))),0) +',    DTPREV = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DTPREV,20)))+''',120)','NULL')+',    VALPREV = '+ ISNULL(LTRIM(RTRIM(CAST(VALPREV AS CHAR(254)))),0) +',    TPO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(TPO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    FILIAL = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(FILIAL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    NUMORD = '+ ISNULL(LTRIM(RTRIM(CAST(NUMORD AS CHAR(254)))),0) +',    TIPOPAR = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(TIPOPAR AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    NUMDOC = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NUMDOC AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    COMPLDOC = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(COMPLDOC AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    LOCALPORTA = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(LOCALPORTA AS CHAR(254)))),0) +'**],    CONTAPORTA = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(CONTAPORTA AS CHAR(254)))),0) +'**],    NUMPARC = '+ ISNULL(LTRIM(RTRIM(CAST(NUMPARC AS CHAR(254)))),0) +',    VALPARC = '+ ISNULL(LTRIM(RTRIM(CAST(VALPARC AS CHAR(254)))),0) +',    TIPODOC = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(TIPODOC AS CHAR(254)))),0) +'**],    OIDCLIENTE = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(OIDCLIENTE AS CHAR(254)))),0) +'**],    ITEM = '+ ISNULL(LTRIM(RTRIM(CAST(ITEM AS CHAR(254)))),0) +',    OIDPREVFLUXO = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(OIDPREVFLUXO AS CHAR(254)))),0) +'**],    RDOCDEORIGEM = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(RDOCDEORIGEM AS CHAR(254)))),0) +'**],    RECEBIDO = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,RECEBIDO,20)))+''',120)','NULL')+',    RCARENCIAPARCELA = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(RCARENCIAPARCELA AS CHAR(254)))),0) +'**],    RECDOCENTREGA = '+ ISNULL(LTRIM(RTRIM(CAST(RECDOCENTREGA AS CHAR(254)))),0) +',    TACEMPRESA = '+ ISNULL(LTRIM(RTRIM(CAST(TACEMPRESA AS CHAR(254)))),0) +',    TACFINANCEIRA = '+ ISNULL(LTRIM(RTRIM(CAST(TACFINANCEIRA AS CHAR(254)))),0) +',    FATOR1 = '+ ISNULL(LTRIM(RTRIM(CAST(FATOR1 AS CHAR(254)))),0) +',    FATOR2 = '+ ISNULL(LTRIM(RTRIM(CAST(FATOR2 AS CHAR(254)))),0) +',    TEMPROMOCAO = '+ ISNULL(LTRIM(RTRIM(CAST(TEMPROMOCAO AS CHAR(254)))),0) +',    VALREC = '+ ISNULL(LTRIM(RTRIM(CAST(VALREC AS CHAR(254)))),0) +',    SEGUROEMPRESA = '+ ISNULL(LTRIM(RTRIM(CAST(SEGUROEMPRESA AS CHAR(254)))),0) +',    SEGUROFINANCEIRA = '+ ISNULL(LTRIM(RTRIM(CAST(SEGUROFINANCEIRA AS CHAR(254)))),0) +',    INFOCHEQUE = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(INFOCHEQUE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    RTIPOAPROVACAO = '+ ISNULL(LTRIM(RTRIM(CAST(RTIPOAPROVACAO AS CHAR(254)))),0) +',    GRUPOAPROVACAO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(GRUPOAPROVACAO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    APROVACAOTRS = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(APROVACAOTRS AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    ARQCARNETRS = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ARQCARNETRS AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    DATAESTORNO = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DATAESTORNO,20)))+''',120)','NULL')+',    PROPOSTATRS = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(PROPOSTATRS AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    STATUSPROPOSTATRS = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(STATUSPROPOSTATRS AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    VALPREVMOEDA2 = '+ ISNULL(LTRIM(RTRIM(CAST(VALPREVMOEDA2 AS CHAR(254)))),0) +',    VALPREVTX = '+ ISNULL(LTRIM(RTRIM(CAST(VALPREVTX AS CHAR(254)))),0) +',    ARQRETTRS = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ARQRETTRS AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    VALPREVLIQUIDO = '+ ISNULL(LTRIM(RTRIM(CAST(VALPREVLIQUIDO AS CHAR(254)))),0) +',    DATAPROPOSTATRS = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DATAPROPOSTATRS,20)))+''',120)','NULL')+',    FILIALRECEBIMENTO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(FILIALRECEBIMENTO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CARENCIA = '+ ISNULL(LTRIM(RTRIM(CAST(CARENCIA AS CHAR(254)))),0) +',    CODIGOBARRA = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODIGOBARRA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    NOMEEMITENTE = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NOMEEMITENTE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CNPJEMITENTE = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CNPJEMITENTE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    ITEMPAI = '+ ISNULL(LTRIM(RTRIM(CAST(ITEMPAI AS CHAR(254)))),0) +',    OIDCONTRATOSERVICO = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(OIDCONTRATOSERVICO AS CHAR(254)))),0) +'**],    NUMCONTRATOSERVICO = '+ ISNULL(LTRIM(RTRIM(CAST(NUMCONTRATOSERVICO AS CHAR(254)))),0) +',    TIPOITEM = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(TIPOITEM AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''''+  ' WHERE item = '+ ISNULL(LTRIM(RTRIM(CAST((@@spid*-1) AS CHAR(254)))),0) , 'PREVCLICAD' FROM inserted
 else
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )    SELECT getdate(), null,'UPDATE PREVCLICAD SET     NUMPED = '+ ISNULL(LTRIM(RTRIM(CAST(NUMPED AS CHAR(254)))),0) +',    DTPREV = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DTPREV,20)))+''',120)','NULL')+',    VALPREV = '+ ISNULL(LTRIM(RTRIM(CAST(VALPREV AS CHAR(254)))),0) +',    TPO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(TPO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    FILIAL = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(FILIAL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    NUMORD = '+ ISNULL(LTRIM(RTRIM(CAST(NUMORD AS CHAR(254)))),0) +',    TIPOPAR = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(TIPOPAR AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    NUMDOC = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NUMDOC AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    COMPLDOC = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(COMPLDOC AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    LOCALPORTA = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(LOCALPORTA AS CHAR(254)))),0) +'**],    CONTAPORTA = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(CONTAPORTA AS CHAR(254)))),0) +'**],    NUMPARC = '+ ISNULL(LTRIM(RTRIM(CAST(NUMPARC AS CHAR(254)))),0) +',    VALPARC = '+ ISNULL(LTRIM(RTRIM(CAST(VALPARC AS CHAR(254)))),0) +',    TIPODOC = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(TIPODOC AS CHAR(254)))),0) +'**],    OIDCLIENTE = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(OIDCLIENTE AS CHAR(254)))),0) +'**],    ITEM = '+ ISNULL(LTRIM(RTRIM(CAST(ITEM AS CHAR(254)))),0) +',    OIDPREVFLUXO = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(OIDPREVFLUXO AS CHAR(254)))),0) +'**],    RDOCDEORIGEM = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(RDOCDEORIGEM AS CHAR(254)))),0) +'**],    RECEBIDO = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,RECEBIDO,20)))+''',120)','NULL')+',    RCARENCIAPARCELA = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(RCARENCIAPARCELA AS CHAR(254)))),0) +'**],    RECDOCENTREGA = '+ ISNULL(LTRIM(RTRIM(CAST(RECDOCENTREGA AS CHAR(254)))),0) +',    TACEMPRESA = '+ ISNULL(LTRIM(RTRIM(CAST(TACEMPRESA AS CHAR(254)))),0) +',    TACFINANCEIRA = '+ ISNULL(LTRIM(RTRIM(CAST(TACFINANCEIRA AS CHAR(254)))),0) +',    FATOR1 = '+ ISNULL(LTRIM(RTRIM(CAST(FATOR1 AS CHAR(254)))),0) +',    FATOR2 = '+ ISNULL(LTRIM(RTRIM(CAST(FATOR2 AS CHAR(254)))),0) +',    TEMPROMOCAO = '+ ISNULL(LTRIM(RTRIM(CAST(TEMPROMOCAO AS CHAR(254)))),0) +',    VALREC = '+ ISNULL(LTRIM(RTRIM(CAST(VALREC AS CHAR(254)))),0) +',    SEGUROEMPRESA = '+ ISNULL(LTRIM(RTRIM(CAST(SEGUROEMPRESA AS CHAR(254)))),0) +',    SEGUROFINANCEIRA = '+ ISNULL(LTRIM(RTRIM(CAST(SEGUROFINANCEIRA AS CHAR(254)))),0) +',    INFOCHEQUE = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(INFOCHEQUE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    RTIPOAPROVACAO = '+ ISNULL(LTRIM(RTRIM(CAST(RTIPOAPROVACAO AS CHAR(254)))),0) +',    GRUPOAPROVACAO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(GRUPOAPROVACAO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    APROVACAOTRS = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(APROVACAOTRS AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    ARQCARNETRS = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ARQCARNETRS AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    DATAESTORNO = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DATAESTORNO,20)))+''',120)','NULL')+',    PROPOSTATRS = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(PROPOSTATRS AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    STATUSPROPOSTATRS = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(STATUSPROPOSTATRS AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    VALPREVMOEDA2 = '+ ISNULL(LTRIM(RTRIM(CAST(VALPREVMOEDA2 AS CHAR(254)))),0) +',    VALPREVTX = '+ ISNULL(LTRIM(RTRIM(CAST(VALPREVTX AS CHAR(254)))),0) +',    ARQRETTRS = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ARQRETTRS AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    VALPREVLIQUIDO = '+ ISNULL(LTRIM(RTRIM(CAST(VALPREVLIQUIDO AS CHAR(254)))),0) +',    DATAPROPOSTATRS = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DATAPROPOSTATRS,20)))+''',120)','NULL')+',    FILIALRECEBIMENTO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(FILIALRECEBIMENTO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CARENCIA = '+ ISNULL(LTRIM(RTRIM(CAST(CARENCIA AS CHAR(254)))),0) +',    CODIGOBARRA = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODIGOBARRA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    NOMEEMITENTE = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NOMEEMITENTE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CNPJEMITENTE = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CNPJEMITENTE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    ITEMPAI = '+ ISNULL(LTRIM(RTRIM(CAST(ITEMPAI AS CHAR(254)))),0) +',    OIDCONTRATOSERVICO = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(OIDCONTRATOSERVICO AS CHAR(254)))),0) +'**],    NUMCONTRATOSERVICO = '+ ISNULL(LTRIM(RTRIM(CAST(NUMCONTRATOSERVICO AS CHAR(254)))),0) +',    TIPOITEM = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(TIPOITEM AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''''+  ' WHERE item = '+ RTRIM(CAST(item as char(254))) +  ''   , 'PREVCLICAD' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'PREVPARCELA_D' AND type = 'TR')
  drop trigger PREVPARCELA_D
go
create trigger dbo.PREVPARCELA_D on dbo.PREVPARCELA for delete as
    Begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
            SELECT getdate(), null,'DELETE FROM PREVPARCELA WHERE 
ritemprev = '+ RTRIM(LTRIM(CAST(ritemprev as char(120)))) + '  and     VENCIMENTO = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,VENCIMENTO,20)))+''',120)','NULL') +'','PREVPARCELA' from deleted
    End
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'PREVPARCELA_I' AND type = 'TR')
   drop trigger PREVPARCELA_I
go
create trigger dbo.PREVPARCELA_I on dbo.PREVPARCELA for insert as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
    SELECT getdate(), null,'INSERT INTO PREVPARCELA(
        RITEMPREV,    VALOR,    VENCIMENTO,    NUMCHEQUE,    BANCO,    AGENCIA,    CONTA,    RECDOCENTREGA)
    VALUES (
    '+ ISNULL(LTRIM(RTRIM(CAST(RITEMPREV AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(VALOR AS CHAR(254)))),0) +','+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,VENCIMENTO,20 ))) +''',120)','NULL')+','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NUMCHEQUE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(BANCO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(AGENCIA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CONTA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(RECDOCENTREGA AS CHAR(254)))),0) +'
     '+ ')', 'PREVPARCELA' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'PREVPARCELA_U' AND type = 'TR')
   drop trigger PREVPARCELA_U
go
create trigger dbo.PREVPARCELA_U on dbo.PREVPARCELA for update as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )    SELECT getdate(), null,'UPDATE PREVPARCELA SET     VALOR = '+ ISNULL(LTRIM(RTRIM(CAST(VALOR AS CHAR(254)))),0) +',    NUMCHEQUE = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NUMCHEQUE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    BANCO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(BANCO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    AGENCIA = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(AGENCIA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    CONTA = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CONTA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    RECDOCENTREGA = '+ ISNULL(LTRIM(RTRIM(CAST(RECDOCENTREGA AS CHAR(254)))),0) +''+  ' WHERE ritemprev = '+ RTRIM(CAST(ritemprev as char(254))) +  ' and     VENCIMENTO = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,VENCIMENTO,20)))+''',120)','NULL') , 'PREVPARCELA' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'RESERVALOTE_D' AND type = 'TR')
  drop trigger RESERVALOTE_D
go
create trigger dbo.RESERVALOTE_D on dbo.RESERVALOTE for delete as
    Begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
            SELECT getdate(), null,'DELETE FROM RESERVALOTE WHERE 
Filial = '''+ RTRIM(LTRIM(Filial)) + '''  and NumPed = '+ RTRIM(LTRIM(CAST(NumPed as char(120)))) + '  and CodPro = '''+ RTRIM(LTRIM(CodPro)) + '''  and LoteInterno = '''+ RTRIM(LTRIM(LoteInterno)) + '''  and ReservadoPor = '''+ RTRIM(LTRIM(ReservadoPor)) + '''  and RItem = '+ RTRIM(LTRIM(CAST(RItem as char(120)))) + '  and numord = '+ RTRIM(LTRIM(CAST(numord as char(120)))) + ' ','RESERVALOTE' from deleted
    End
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'RESERVALOTE_I' AND type = 'TR')
   drop trigger RESERVALOTE_I
go
create trigger dbo.RESERVALOTE_I on dbo.RESERVALOTE for insert as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
    SELECT getdate(), null,'INSERT INTO RESERVALOTE(
        FILIAL,    NUMPED,    CODPRO,    LOTEINTERNO,    QUANT,    RESERVADOPOR,    RITEM,    NUMORD,    QTDCONFERIDO,    LOTEINTERNOANTERIOR,    RESERVAAUTOMATICA,    DATARESERVA,    ITEMCOMP,    RESERVOUSALDOFINAL)
    VALUES (
    '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(FILIAL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(NUMPED AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODPRO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LOTEINTERNO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(QUANT AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(RESERVADOPOR AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(RITEM AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(NUMORD AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(QTDCONFERIDO AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LOTEINTERNOANTERIOR AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(RESERVAAUTOMATICA AS CHAR(254)))),0) +','+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DATARESERVA,20 ))) +''',120)','NULL')+','+ ISNULL(LTRIM(RTRIM(CAST(ITEMCOMP AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(RESERVOUSALDOFINAL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +'''
     '+ ')', 'RESERVALOTE' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'RESERVALOTE_U' AND type = 'TR')
   drop trigger RESERVALOTE_U
go
create trigger dbo.RESERVALOTE_U on dbo.RESERVALOTE for update as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )    SELECT getdate(), null,'UPDATE RESERVALOTE SET     QUANT = '+ ISNULL(LTRIM(RTRIM(CAST(QUANT AS CHAR(254)))),0) +',    QTDCONFERIDO = '+ ISNULL(LTRIM(RTRIM(CAST(QTDCONFERIDO AS CHAR(254)))),0) +',    LOTEINTERNOANTERIOR = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LOTEINTERNOANTERIOR AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    RESERVAAUTOMATICA = '+ ISNULL(LTRIM(RTRIM(CAST(RESERVAAUTOMATICA AS CHAR(254)))),0) +',    DATARESERVA = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DATARESERVA,20)))+''',120)','NULL')+',    ITEMCOMP = '+ ISNULL(LTRIM(RTRIM(CAST(ITEMCOMP AS CHAR(254)))),0) +',    RESERVOUSALDOFINAL = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(RESERVOUSALDOFINAL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''''+  ' WHERE Filial = '''+ RTRIM(Filial)  + ''' and NumPed = '+ RTRIM(CAST(NumPed as char(254))) +  ' and CodPro = '''+ RTRIM(CodPro)  + ''' and LoteInterno = '''+ RTRIM(LoteInterno)  + ''' and ReservadoPor = '''+ RTRIM(ReservadoPor)  + ''' and RItem = '+ RTRIM(CAST(RItem as char(254))) +  ' and numord = '+ RTRIM(CAST(numord as char(254))) +  ''   , 'RESERVALOTE' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'SAIDALOTE_D' AND type = 'TR')
  drop trigger SAIDALOTE_D
go
create trigger dbo.SAIDALOTE_D on dbo.SAIDALOTE for delete as
    Begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
            SELECT getdate(), null,'DELETE FROM SAIDALOTE WHERE 
Filial = '''+ RTRIM(LTRIM(Filial)) + '''  and NumOrd = '+ RTRIM(LTRIM(CAST(NumOrd as char(120)))) + '  and CodPro = '''+ RTRIM(LTRIM(CodPro)) + '''  and LoteInterno = '''+ RTRIM(LTRIM(LoteInterno)) + '''  and RItem = '''+ RTRIM(LTRIM(RItem)) + '''  and ITEMPEDIDO = '+ RTRIM(LTRIM(CAST(ITEMPEDIDO as char(120)))) + ' ','SAIDALOTE' from deleted
    End
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'SAIDALOTE_I' AND type = 'TR')
   drop trigger SAIDALOTE_I
go
create trigger dbo.SAIDALOTE_I on dbo.SAIDALOTE for insert as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
    SELECT getdate(), null,'INSERT INTO SAIDALOTE(
        FILIAL,    NUMORD,    CODPRO,    LOTEINTERNO,    QUANT,    RITEM,    ATUALIZADO,    ITEMPEDIDO)
    VALUES (
    '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(FILIAL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(NUMORD AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODPRO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(LOTEINTERNO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(QUANT AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(RITEM AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(ATUALIZADO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ITEMPEDIDO AS CHAR(254)))),0) +'
     '+ ')', 'SAIDALOTE' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'SAIDALOTE_U' AND type = 'TR')
   drop trigger SAIDALOTE_U
go
create trigger dbo.SAIDALOTE_U on dbo.SAIDALOTE for update as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )    SELECT getdate(), null,'UPDATE SAIDALOTE SET     QUANT = '+ ISNULL(LTRIM(RTRIM(CAST(QUANT AS CHAR(254)))),0) +',    ATUALIZADO = '+ ISNULL(LTRIM(RTRIM(CAST(ATUALIZADO AS CHAR(254)))),0) +''+  ' WHERE Filial = '''+ RTRIM(Filial)  + ''' and NumOrd = '+ RTRIM(CAST(NumOrd as char(254))) +  ' and CodPro = '''+ RTRIM(CodPro)  + ''' and LoteInterno = '''+ RTRIM(LoteInterno)  + ''' and RItem = '''+ RTRIM(RItem)  + ''' and ITEMPEDIDO = '+ RTRIM(CAST(ITEMPEDIDO as char(254))) +  ''   , 'SAIDALOTE' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'SANGRIACAD_D' AND type = 'TR')
  drop trigger SANGRIACAD_D
go
create trigger dbo.SANGRIACAD_D on dbo.SANGRIACAD for delete as
    Begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
            SELECT getdate(), null,'DELETE FROM SANGRIACAD WHERE 
filial = '''+ RTRIM(LTRIM(filial)) + '''  and caixa =  [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(CAIXA AS CHAR(254)))),0) +'**] and     DATA = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DATA,20)))+''',120)','NULL') +' and documen =  [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(DOCUMEN AS CHAR(254)))),0) +'**]','SANGRIACAD' from deleted
    End
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'SANGRIACAD_I' AND type = 'TR')
   drop trigger SANGRIACAD_I
go
create trigger dbo.SANGRIACAD_I on dbo.SANGRIACAD for insert as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
    SELECT getdate(), null,'INSERT INTO SANGRIACAD(
        FILIAL,    CAIXA,    DATA,    DOCUMEN,    TIPOPAG,    VLRSANGRIA,    NUMORDDEV,    USULIBDEVCRED,    ITEM)
    VALUES (
    '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(FILIAL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',  [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(CAIXA AS CHAR(254)))),0) +'**],'+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DATA,20 ))) +''',120)','NULL')+',  [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(DOCUMEN AS CHAR(254)))),0) +'**],'''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(TIPOPAG AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(VLRSANGRIA AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(NUMORDDEV AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(USULIBDEVCRED AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ITEM AS CHAR(254)))),0) +'
     '+ ')', 'SANGRIACAD' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'SANGRIACAD_U' AND type = 'TR')
   drop trigger SANGRIACAD_U
go
create trigger dbo.SANGRIACAD_U on dbo.SANGRIACAD for update as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )    SELECT getdate(), null,'UPDATE SANGRIACAD SET     TIPOPAG = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(TIPOPAG AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    VLRSANGRIA = '+ ISNULL(LTRIM(RTRIM(CAST(VLRSANGRIA AS CHAR(254)))),0) +',    NUMORDDEV = '+ ISNULL(LTRIM(RTRIM(CAST(NUMORDDEV AS CHAR(254)))),0) +',    USULIBDEVCRED = '+ ISNULL(LTRIM(RTRIM(CAST(USULIBDEVCRED AS CHAR(254)))),0) +',    ITEM = '+ ISNULL(LTRIM(RTRIM(CAST(ITEM AS CHAR(254)))),0) +''+  ' WHERE filial = '''+ RTRIM(filial)  + ''' and     caixa = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(caixa AS CHAR(254)))),0) +'**] and     DATA = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DATA,20)))+''',120)','NULL')+' and     documen = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(documen AS CHAR(254)))),0) +'**]'  , 'SANGRIACAD' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'SERIALECF_D' AND type = 'TR')
  drop trigger SERIALECF_D
go
create trigger dbo.SERIALECF_D on dbo.SERIALECF for delete as
    Begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
            SELECT getdate(), null,'DELETE FROM SERIALECF WHERE 
SERIALIMPRESSORA = '''+ RTRIM(LTRIM(SERIALIMPRESSORA)) + ''' ','SERIALECF' from deleted
    End
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'SERIALECF_I' AND type = 'TR')
   drop trigger SERIALECF_I
go
create trigger dbo.SERIALECF_I on dbo.SERIALECF for insert as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
    SELECT getdate(), null,'INSERT INTO SERIALECF(
        MODELO,    MARCA,    VERSAODLL,    TIPO,    MFADICIONAL,    CNIECF,    VERSAOSB,    DATAGRAVASB,    OIDIMPRESSORA,    SERIALIMPRESSORA,    CODIMP,    OID)
    VALUES (
    '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(MODELO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(MARCA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(VERSAODLL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(TIPO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(MFADICIONAL AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CNIECF AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(VERSAOSB AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DATAGRAVASB,20 ))) +''',120)','NULL')+',  [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(OIDIMPRESSORA AS CHAR(254)))),0) +'**],'''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(SERIALIMPRESSORA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(CODIMP AS CHAR(254)))),0) +',  [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(OID AS CHAR(254)))),0) +'**]
     '+ ')', 'SERIALECF' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'SERIALECF_U' AND type = 'TR')
   drop trigger SERIALECF_U
go
create trigger dbo.SERIALECF_U on dbo.SERIALECF for update as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )    SELECT getdate(), null,'UPDATE SERIALECF SET     MODELO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(MODELO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    MARCA = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(MARCA AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    VERSAODLL = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(VERSAODLL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    TIPO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(TIPO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    MFADICIONAL = '+ ISNULL(LTRIM(RTRIM(CAST(MFADICIONAL AS CHAR(254)))),0) +',    CNIECF = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CNIECF AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    VERSAOSB = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(VERSAOSB AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    DATAGRAVASB = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DATAGRAVASB,20)))+''',120)','NULL')+',    OIDIMPRESSORA = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(OIDIMPRESSORA AS CHAR(254)))),0) +'**],    CODIMP = '+ ISNULL(LTRIM(RTRIM(CAST(CODIMP AS CHAR(254)))),0) +',    OID = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(OID AS CHAR(254)))),0) +'**]'+  ' WHERE SERIALIMPRESSORA = '''+ RTRIM(SERIALIMPRESSORA)  + ''''   , 'SERIALECF' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'TEXLIVRFAT_D' AND type = 'TR')
  drop trigger TEXLIVRFAT_D
go
create trigger dbo.TEXLIVRFAT_D on dbo.TEXLIVRFAT for delete as
    Begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
            SELECT getdate(), null,'DELETE FROM TEXLIVRFAT WHERE 
Item = '+ RTRIM(LTRIM(CAST(Item as char(120)))) + ' ','TEXLIVRFAT' from deleted
    End
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'TEXLIVRFAT_INST_I' AND type = 'TR')
   drop trigger TEXLIVRFAT_INST_I
go
create trigger dbo.TEXLIVRFAT_INST_I on dbo.TEXLIVRFAT INSTEAD OF insert as
begin
    SELECT * INTO #Inserted FROM Inserted
    UPDATE #Inserted SET item = (@@spid*-1)
    INSERT INTO TEXLIVRFAT SELECT * FROM #Inserted
    Return
end
go
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'TEXLIVRFAT_I' AND type = 'TR')
   drop trigger TEXLIVRFAT_I
go
create trigger dbo.TEXLIVRFAT_I on dbo.TEXLIVRFAT for insert as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
    SELECT getdate(), null,'INSERT INTO TEXLIVRFAT(
        NUMORD,    TEXTO,    NUMORDFIS,    IMPOGER,    ITEM)
    VALUES (
    '+ ISNULL(LTRIM(RTRIM(CAST(NUMORD AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(TEXTO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(NUMORDFIS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(IMPOGER AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ITEM AS CHAR(254)))),0) +'
     '+ ')', 'TEXLIVRFAT' FROM inserted
    declare @nContador integer
    exec GERASEMENTE_P 'TW_IDENTIFICADOR', 7, @nContador OUTPUT
    if @nContador > 0
      update TEXLIVRFAT set ITEM = @nContador WHERE ITEM = (select ITEM from inserted WHERE ITEM=(@@spid*-1))
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'TEXLIVRFAT_U' AND type = 'TR')
   drop trigger TEXLIVRFAT_U
go
create trigger dbo.TEXLIVRFAT_U on dbo.TEXLIVRFAT for update as
begin
  if (select count(*) from deleted where item = @@spid*-1 ) > 0
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )    SELECT getdate(), null,'UPDATE TEXLIVRFAT SET     NUMORD = '+ ISNULL(LTRIM(RTRIM(CAST(NUMORD AS CHAR(254)))),0) +',    TEXTO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(TEXTO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    NUMORDFIS = '+ ISNULL(LTRIM(RTRIM(CAST(NUMORDFIS AS CHAR(254)))),0) +',    IMPOGER = '+ ISNULL(LTRIM(RTRIM(CAST(IMPOGER AS CHAR(254)))),0) +',    ITEM = '+ ISNULL(LTRIM(RTRIM(CAST(ITEM AS CHAR(254)))),0) +''+  ' WHERE item = '+ ISNULL(LTRIM(RTRIM(CAST((@@spid*-1) AS CHAR(254)))),0) , 'TEXLIVRFAT' FROM inserted
 else
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )    SELECT getdate(), null,'UPDATE TEXLIVRFAT SET     NUMORD = '+ ISNULL(LTRIM(RTRIM(CAST(NUMORD AS CHAR(254)))),0) +',    TEXTO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(TEXTO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    NUMORDFIS = '+ ISNULL(LTRIM(RTRIM(CAST(NUMORDFIS AS CHAR(254)))),0) +',    IMPOGER = '+ ISNULL(LTRIM(RTRIM(CAST(IMPOGER AS CHAR(254)))),0) +',    ITEM = '+ ISNULL(LTRIM(RTRIM(CAST(ITEM AS CHAR(254)))),0) +''+  ' WHERE Item = '+ RTRIM(CAST(Item as char(254))) +  ''   , 'TEXLIVRFAT' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'TRANSACAOCARTAO_D' AND type = 'TR')
  drop trigger TRANSACAOCARTAO_D
go
create trigger dbo.TRANSACAOCARTAO_D on dbo.TRANSACAOCARTAO for delete as
    Begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
            SELECT getdate(), null,'DELETE FROM TRANSACAOCARTAO WHERE 
ITEM = '+ RTRIM(LTRIM(CAST(ITEM as char(120)))) + ' ','TRANSACAOCARTAO' from deleted
    End
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'TRANSACAOCARTAO_I' AND type = 'TR')
   drop trigger TRANSACAOCARTAO_I
go
create trigger dbo.TRANSACAOCARTAO_I on dbo.TRANSACAOCARTAO for insert as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
    SELECT getdate(), null,'INSERT INTO TRANSACAOCARTAO(
        ITEM,    NSU_SITEF,    NSU_ADMINISTRADORA,    AUTORIZACAO,    NUMPARC,    ESTABELECIMENTO,    TERMINAL,    ATIVA,    RITEMPREVCLI)
    VALUES (
    '+ ISNULL(LTRIM(RTRIM(CAST(ITEM AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(NSU_SITEF AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(NSU_ADMINISTRADORA AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(AUTORIZACAO AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(NUMPARC AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ESTABELECIMENTO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(TERMINAL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(ATIVA AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(RITEMPREVCLI AS CHAR(254)))),0) +'
     '+ ')', 'TRANSACAOCARTAO' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'TRANSACAOCARTAO_U' AND type = 'TR')
   drop trigger TRANSACAOCARTAO_U
go
create trigger dbo.TRANSACAOCARTAO_U on dbo.TRANSACAOCARTAO for update as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )    SELECT getdate(), null,'UPDATE TRANSACAOCARTAO SET     NSU_SITEF = '+ ISNULL(LTRIM(RTRIM(CAST(NSU_SITEF AS CHAR(254)))),0) +',    NSU_ADMINISTRADORA = '+ ISNULL(LTRIM(RTRIM(CAST(NSU_ADMINISTRADORA AS CHAR(254)))),0) +',    AUTORIZACAO = '+ ISNULL(LTRIM(RTRIM(CAST(AUTORIZACAO AS CHAR(254)))),0) +',    NUMPARC = '+ ISNULL(LTRIM(RTRIM(CAST(NUMPARC AS CHAR(254)))),0) +',    ESTABELECIMENTO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(ESTABELECIMENTO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    TERMINAL = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(TERMINAL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    ATIVA = '+ ISNULL(LTRIM(RTRIM(CAST(ATIVA AS CHAR(254)))),0) +',    RITEMPREVCLI = '+ ISNULL(LTRIM(RTRIM(CAST(RITEMPREVCLI AS CHAR(254)))),0) +''+  ' WHERE ITEM = '+ RTRIM(CAST(ITEM as char(254))) +  ''   , 'TRANSACAOCARTAO' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'VENDASSCAD_D' AND type = 'TR')
  drop trigger VENDASSCAD_D
go
create trigger dbo.VENDASSCAD_D on dbo.VENDASSCAD for delete as
    Begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
            SELECT getdate(), null,'DELETE FROM VENDASSCAD WHERE 
numord = '+ RTRIM(LTRIM(CAST(numord as char(120)))) + ' ','VENDASSCAD' from deleted
    End
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'VENDASSCAD_I' AND type = 'TR')
   drop trigger VENDASSCAD_I
go
create trigger dbo.VENDASSCAD_I on dbo.VENDASSCAD for insert as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
    SELECT getdate(), null,'INSERT INTO VENDASSCAD(
        NUMORD,    FILIAL,    LOCALPORTA,    DTVEN,    USUVEN,    NUMPED,    TOTVEN,    FRETEORC,    NUMFRETE,    DTENTR,    CODTRAN,    NORDFRETE,    SITUACAO,    RECEBER,    TAXANF,    OIDDOCDEORIGEM,    CONDPAGPOSTERIOR,    PENDENTE,    MANUAL,    OUTRASDESPESASINCLUSAS,    TOTRECANTECIPADO,    TIPO)
    VALUES (
    '+ ISNULL(LTRIM(RTRIM(CAST(NUMORD AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(FILIAL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',  [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(LOCALPORTA AS CHAR(254)))),0) +'**],'+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DTVEN,20 ))) +''',120)','NULL')+','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(USUVEN AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(NUMPED AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(TOTVEN AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(FRETEORC AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NUMFRETE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DTENTR,20 ))) +''',120)','NULL')+','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODTRAN AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(NORDFRETE AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(SITUACAO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(RECEBER AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','+ ISNULL(LTRIM(RTRIM(CAST(TAXANF AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(OIDDOCDEORIGEM AS CHAR(254)))),0) +',  [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(CONDPAGPOSTERIOR AS CHAR(254)))),0) +'**],'+ ISNULL(LTRIM(RTRIM(CAST(PENDENTE AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(MANUAL AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(OUTRASDESPESASINCLUSAS AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(TOTRECANTECIPADO AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(TIPO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +'''
     '+ ')', 'VENDASSCAD' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'VENDASSCAD_U' AND type = 'TR')
   drop trigger VENDASSCAD_U
go
create trigger dbo.VENDASSCAD_U on dbo.VENDASSCAD for update as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )    SELECT getdate(), null,'UPDATE VENDASSCAD SET     FILIAL = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(FILIAL AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    LOCALPORTA = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(LOCALPORTA AS CHAR(254)))),0) +'**],    DTVEN = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DTVEN,20)))+''',120)','NULL')+',    USUVEN = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(USUVEN AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    NUMPED = '+ ISNULL(LTRIM(RTRIM(CAST(NUMPED AS CHAR(254)))),0) +',    TOTVEN = '+ ISNULL(LTRIM(RTRIM(CAST(TOTVEN AS CHAR(254)))),0) +',    FRETEORC = '+ ISNULL(LTRIM(RTRIM(CAST(FRETEORC AS CHAR(254)))),0) +',    NUMFRETE = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(NUMFRETE AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    DTENTR = '+ ISNULL( +'CONVERT(DATETIME,'''+ LTRIM(RTRIM(CONVERT(CHAR,DTENTR,20)))+''',120)','NULL')+',    CODTRAN = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(CODTRAN AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    NORDFRETE = '+ ISNULL(LTRIM(RTRIM(CAST(NORDFRETE AS CHAR(254)))),0) +',    SITUACAO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(SITUACAO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    RECEBER = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(RECEBER AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    TAXANF = '+ ISNULL(LTRIM(RTRIM(CAST(TAXANF AS CHAR(254)))),0) +',    OIDDOCDEORIGEM = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(OIDDOCDEORIGEM AS CHAR(254)))),0) +'**],    CONDPAGPOSTERIOR = [**RELAC'+ ISNULL(LTRIM(RTRIM(CAST(CONDPAGPOSTERIOR AS CHAR(254)))),0) +'**],    PENDENTE = '+ ISNULL(LTRIM(RTRIM(CAST(PENDENTE AS CHAR(254)))),0) +',    MANUAL = '+ ISNULL(LTRIM(RTRIM(CAST(MANUAL AS CHAR(254)))),0) +',    OUTRASDESPESASINCLUSAS = '+ ISNULL(LTRIM(RTRIM(CAST(OUTRASDESPESASINCLUSAS AS CHAR(254)))),0) +',    TOTRECANTECIPADO = '+ ISNULL(LTRIM(RTRIM(CAST(TOTRECANTECIPADO AS CHAR(254)))),0) +',    TIPO = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(TIPO AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''''+  ' WHERE numord = '+ RTRIM(CAST(numord as char(254))) +  ''   , 'VENDASSCAD' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'VENDATEXTOPADRAO_D' AND type = 'TR')
  drop trigger VENDATEXTOPADRAO_D
go
create trigger dbo.VENDATEXTOPADRAO_D on dbo.VENDATEXTOPADRAO for delete as
    Begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
            SELECT getdate(), null,'DELETE FROM VENDATEXTOPADRAO WHERE 
numped = '+ RTRIM(LTRIM(CAST(numped as char(120)))) + '  and item = '+ RTRIM(LTRIM(CAST(item as char(120)))) + ' ','VENDATEXTOPADRAO' from deleted
    End
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'VENDATEXTOPADRAO_I' AND type = 'TR')
   drop trigger VENDATEXTOPADRAO_I
go
create trigger dbo.VENDATEXTOPADRAO_I on dbo.VENDATEXTOPADRAO for insert as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )
    SELECT getdate(), null,'INSERT INTO VENDATEXTOPADRAO(
        NUMPED,    ITEM,    DESCR,    DESCTEXT2,    DESCTEXT3,    DESCTEXT4,    DESCTEXT5,    TIPOENTSAI)
    VALUES (
    '+ ISNULL(LTRIM(RTRIM(CAST(NUMPED AS CHAR(254)))),0) +','+ ISNULL(LTRIM(RTRIM(CAST(ITEM AS CHAR(254)))),0) +','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(DESCR AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(DESCTEXT2 AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(DESCTEXT3 AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(DESCTEXT4 AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(DESCTEXT5 AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''','''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(TIPOENTSAI AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +'''
     '+ ')', 'VENDATEXTOPADRAO' FROM inserted
    return
end
go
 
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'VENDATEXTOPADRAO_U' AND type = 'TR')
   drop trigger VENDATEXTOPADRAO_U
go
create trigger dbo.VENDATEXTOPADRAO_U on dbo.VENDATEXTOPADRAO for update as
begin
    insert into REPLICACAO_LOJA(CRIADOEM, PROCESSADOEM , COMANDO,TABELA )    SELECT getdate(), null,'UPDATE VENDATEXTOPADRAO SET     DESCR = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(DESCR AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    DESCTEXT2 = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(DESCTEXT2 AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    DESCTEXT3 = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(DESCTEXT3 AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    DESCTEXT4 = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(DESCTEXT4 AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    DESCTEXT5 = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(DESCTEXT5 AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''',    TIPOENTSAI = '''+ REPLACE(REPLACE(REPLACE(ISNULL(LTRIM(RTRIM(CAST(TIPOENTSAI AS CHAR(254)))),''),'''',''),CHAR(13),''),CHAR(10),'') +''''+  ' WHERE numped = '+ RTRIM(CAST(numped as char(254))) +  ' and item = '+ RTRIM(CAST(item as char(254))) +  ''   , 'VENDATEXTOPADRAO' FROM inserted
    return
end
go
 
print 'Termino - Se ocorreu algum erro encaminhar para suporte'
