Himanshu Shukla
Himanshu Shukla

Reputation: 23

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

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;

Upvotes: 1

Views: 48

Answers (1)

P.Salmon
P.Salmon

Reputation: 17665

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.

Upvotes: 1

Related Questions