How to concatenate the return of a query to a string of another mysql

0

I have the following query:

 SELECT 
    id   AS CODIGO,
    nome AS NOME,
    versao AS VERSAO,
    build  AS BUILD,
    data   AS DATA
        FROM sistema 
            INTO OUTFILE 'D:/servicos/export/exportaVersao.csv'
            FIELDS TERMINATED BY ';' ENCLOSED BY '"' LINES TERMINATED BY '\n';

I would like to change the export version to some random number, eg:

'D:/servicos/export/256589.csv'

I got this query that generates this number:

(SELECT FLOOR(10000 + (RAND() * 99999)))

How can I concatenate with each other?

If it is not possible, instead of this random number it could be: 170704 (data = aa/mm/dd)

Attempt to concatenate:

 SELECT  
    id   AS CODIGO,
    nome AS NOME,
    versao AS VERSAO,
    build  AS BUILD,
    data   AS DATA
        FROM sistema 
            INTO OUTFILE concat(concat('D:/servicos/export/','' ,(SELECT FLOOR(10000 + (RAND() * 99999)))),'.','csv')
            FIELDS TERMINATED BY ';' ENCLOSED BY '"' LINES TERMINATED BY '\n';

Error:

  

0 55 01:02:58 SELECT - QUERY             id AS CODE,             name AS NAME,             VERSION VERSION,             build AS BUILD,             date AS DATA              FROM system               INTO OUTFILE concat ('D: / services / export /', '', (SELECT FLOOR (10000 + (RAND () * 99999)))), '.', 'Csv')               FIELDS TERMINATED BY ';' ENCLOSED BY '"' LINES TERMINATED BY '\ n' Error Code: 1064. You have an error in your SQL syntax;   the manual that corresponds to your MariaDB server version for the   right syntax to use near concat (concat ('D: / services / export /', ''   , (SELECT FLOOR (10000 + (RAND () * 99999))) 'at line 8 0.000 sec

    
asked by anonymous 04.07.2017 / 05:13

1 answer

0

Solution:

delimiter |
ALTER EVENT ExportaVersao
    ON SCHEDULE 
        EVERY 5 SECOND
    COMMENT 'Exporta Versão do Sistema'
    DO
      BEGIN
      SET @sql_text = 
        CONCAT ("SELECT * FROM SISTEMA  into outfile 'D:/servicos/export/", 
        DATE_FORMAT( NOW(), '%Y%m%d%H%i%s'), 
        ".csv 'FIELDS TERMINATED BY ';'");
       PREPARE s1 FROM @sql_text;
       EXECUTE s1;
       DROP PREPARE s1;
      END|

delimiter ;
    
04.07.2017 / 07:16