Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

The MySQL version I'm using is 5.1.46. The query is

CREATE DEFINER = CURRENT_USER TRIGGER `movimentacao_before_del_tr` BEFORE DELETE ON `movimentacao`
  FOR EACH ROW
 IF (OLD.stMov IN ("E", "C", "R")) THEN
    INSERT INTO `controle` (
      `tabela`,
      `data`,
      `hora`,
      `registro`
    ) VALUES (
      MD5("movimentacao"),
      OLD.dtEmissao,
      CURTIME(),
      CONCAT_WS("|",
        OLD.idMovimentacao,
        OLD.idEcf,
        OLD.numFabricacao,
        OLD.CCF,
        OLD.stMov,
        OLD.tpNota,
        OLD.modoMov,
        OLD.dtMovimentacao,
        OLD.dtEmissao,
        OLD.hrEmissao,
        OLD.numNF,
        OLD.idPessoa,
        OLD.cpfCnpj,
        OLD.rgIe,
        OLD.nomePessoa,
        OLD.codcidade,
        OLD.uf,
        OLD.cidade,
        OLD.bairro,
        OLD.logradouro,
        OLD.numero,
        OLD.complemento,
        OLD.cep,
        OLD.totalBruto,
        OLD.valAcrecimo,
        OLD.valDesconto,
        OLD.valOutrasDespesas,
        OLD.valFrete,
        OLD.valSeguro,
        OLD.bcICMS,
        OLD.valICMS,
        OLD.bcICMSST,
        OLD.valICMSST,
        OLD.valPIS,
        OLD.valCOFINS,
        OLD.totalLiquido,
        OLD.idNatOp,
        OLD.idAidf,
        OLD.especie,
        OLD.serie,
        OLD.docProprio,
        OLD.chaveNFe,
        OLD.motivoCancelamento,
        OLD.hrMovimentacao,
        OLD.IdTransportador,
        OLD.modFrete,
        OLD.qtdeVolumes,
        OLD.especieVolumes,
        OLD.marcaVolumes,
        OLD.pesoL,
        OLD.pesoB,
        OLD.infAdFisco,
        OLD.infCpl,
        OLD.enderecoTransp,
        OLD.cidadeTransp,
        OLD.UfTransp,
        OLD.finNFe,
        OLD.placaVeicTransp,
        OLD.ufVeicTrans,
        OLD.RNTC,
        OLD.idOperador,
        OLD.chk,
        OLD.hash,
        OLD.hash2
      )
    );
  END IF;

The returned is #1064 - Você tem um erro de sintaxe no seu SQL próximo a '' na linha 79. Translation: You have a MySQL syntax error near to '' on line 79.

The Workbench show an erro at the last line: syntax error, unexpected END_OF_INPUT, expecting ';'

share|improve this question

1 Answer 1

You need to change the delimiter to accept semicolons properly while creating the trigger

DELIMITER $$
CREATE DEFINER = CURRENT_USER TRIGGER `movimentacao_before_del_tr` BEFORE DELETE ON `movimentacao`
  FOR EACH ROW
 IF (OLD.stMov IN ("E", "C", "R")) THEN
    INSERT INTO `controle` (
      `tabela`,
      `data`,
      `hora`,
      `registro`
    ) VALUES (
      MD5("movimentacao"),
      OLD.dtEmissao,
      CURTIME(),
      CONCAT_WS("|",
        OLD.idMovimentacao,
        OLD.idEcf,
        OLD.numFabricacao,
        OLD.CCF,
        OLD.stMov,
        OLD.tpNota,
        OLD.modoMov,
        OLD.dtMovimentacao,
        OLD.dtEmissao,
        OLD.hrEmissao,
        OLD.numNF,
        OLD.idPessoa,
        OLD.cpfCnpj,
        OLD.rgIe,
        OLD.nomePessoa,
        OLD.codcidade,
        OLD.uf,
        OLD.cidade,
        OLD.bairro,
        OLD.logradouro,
        OLD.numero,
        OLD.complemento,
        OLD.cep,
        OLD.totalBruto,
        OLD.valAcrecimo,
        OLD.valDesconto,
        OLD.valOutrasDespesas,
        OLD.valFrete,
        OLD.valSeguro,
        OLD.bcICMS,
        OLD.valICMS,
        OLD.bcICMSST,
        OLD.valICMSST,
        OLD.valPIS,
        OLD.valCOFINS,
        OLD.totalLiquido,
        OLD.idNatOp,
        OLD.idAidf,
        OLD.especie,
        OLD.serie,
        OLD.docProprio,
        OLD.chaveNFe,
        OLD.motivoCancelamento,
        OLD.hrMovimentacao,
        OLD.IdTransportador,
        OLD.modFrete,
        OLD.qtdeVolumes,
        OLD.especieVolumes,
        OLD.marcaVolumes,
        OLD.pesoL,
        OLD.pesoB,
        OLD.infAdFisco,
        OLD.infCpl,
        OLD.enderecoTransp,
        OLD.cidadeTransp,
        OLD.UfTransp,
        OLD.finNFe,
        OLD.placaVeicTransp,
        OLD.ufVeicTrans,
        OLD.RNTC,
        OLD.idOperador,
        OLD.chk,
        OLD.hash,
        OLD.hash2
      )
    );
  END IF $$
DELIMITER ;

Give it a Try !!!

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.