Question : Using concat to generate outfile name

I'm trying to save my query results to /home/mydir/2008-09-05.txt.

Can anyone tell me what's wrong with this syntax?

select * from mytable into outfile 'concat('/home/mydir/',curdate(),'.txt')';

Thanks in advance.

Answer : Using concat to generate outfile name

If you want to use OUTFILE with a variable for the file name you cannot simply put it in place - MySQL will not resolve the name.
But you can do with the following way:
put the whole command into a variable and use "prepare" and "execute"

SELECT @myCommand := concat("SELECT * from mytable into OUTFILE '/home/mysql/archive/", curdate(), ".txt'");
PREPARE stmt FROM @myCommand;
EXECUTE stmt;

Hope this helps....
Random Solutions  
 
programming4us programming4us