Jump to content
Fórum Script Brasil
  • 0

Nomear arquivo de texo com uma variavel into outfile


EAlcantara
 Share

Question

Boa noite.

Eu desejo automatizar a geração de alguns arquivos baseados  no mês, então incluo a variável mês, com o código abaixo eu obtenho os dados que desejo mas não consigo renomear automaticamente o nome do arquivo usando o mês contido na variável.

 

CREATE DEFINER=`root`@`localhost` PROCEDURE `conta0150`(Vmes CHAR(7))
BEGIN
SELECT* FROM part
WHERE cnpj
IN(select DISTINCT(cnpj) FROM nf WHERE ano = Vmes)
INTO OUTFILE 'C:/Uploads/part-2015_01-12.csv'
FIELDS TERMINATED BY ';'
ENCLOSED BY ''
LINES TERMINATED BY '\r\n';
END

 

Tentei fazer o seguinte, mas a sintaxe não é permitida;

 

CREATE DEFINER=`root`@`localhost` PROCEDURE `conta0150`(Vmes CHAR(7))
BEGIN
SELECT* FROM part
WHERE cnpj
IN(select DISTINCT(cnpj) FROM nf WHERE ano = Vmes)
INTO OUTFILE CONCAT(''C:/Uploads/part-',Vmes,'.csv')
FIELDS TERMINATED BY ';'
ENCLOSED BY ''
LINES TERMINATED BY '\r\n'; 
END

 

Estou usando  MYSQL 5.6
Encontrei apenas duvidas de como realizar isso inclusive em outros fóruns, alguém pode me ajudar com essa demanda ? 

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0

A sintaxe correta é:

SELECT * 
INTO OUTFILE 'C:/Uploads/part-2015_01-12.csv'
FIELDS TERMINATED BY ';'
ENCLOSED BY ''
LINES TERMINATED BY '\r\n'
FROM part
WHERE cnpj
IN(select DISTINCT(cnpj) FROM nf WHERE ano = Vmes);

Para usar como variável estude sobre prepared statments 

http://dev.mysql.com/doc/refman/5.7/en/sql-syntax-prepared-statements.html

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share



  • Forum Statistics

    • Total Topics
      149.9k
    • Total Posts
      646.8k
×
×
  • Create New...