how to add date while importing data in csv from mysql query

Viewed 32

need to add date in the file name into outfile caluse below pease suggest

SET @outpath = "/var/lib/mysql-files/";
SET @outfile = (SELECT NOW());
SET @outextension = "_StepCount.csv";
SET @SQL := CONCAT("Select Concat(ifnull(First_Name,'')," ",ifnull(Middle_Name,'')," ",ifnull(Last_name,'')) AS Name, u.email from users",@outpath,@outfile,@outextension ) ;
PREPARE stmt FROM @SQL;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
1 Answers

I prefer to use char(39) (single quote)

SET @SQL := CONCAT("Select Concat(ifnull(First_Name,'')," ",ifnull(Middle_Name,'')," ",ifnull(Last_name,'')) AS Name, u.email from users",
CHAR(39),@outpath,@outfile,@outextension,CHAR(39) ) ;

NB- I haven't corrected the other errors in this code but if you select @sql they should be obvious.

Related