Solved

How can I include today's date in filename .csv when using OUTFILE using MySQL

Posted on 2016-08-11
5
74 Views
Last Modified: 2016-08-11
I need to create export a csv file that should be named with date i.e. file20160811.csv

I have my query.
I tried this:
SET @sql_text = CONCAT("Select * from Table1 into outfile 'C:\desktop\",date_format(NOW(),'%Y%m%d'),".csv'");
PREPARE statement FROM @sql_text;
EXECUTE statement;

I got  error Code 1064, error SQL syntax...

can someone help me to fix this?

Thanks in advance.
0
Comment
Question by:Jerry Seinfield
  • 3
  • 2
5 Comments
 
LVL 41

Accepted Solution

by:
Sharath earned 500 total points
ID: 41752878
SET @sql_text=CONCAT("Select * from Table1 into outfile 'C:\\desktop\\",date_format(NOW(),'%Y%m%d'),".csv'");

Open in new window

0
 

Author Comment

by:Jerry Seinfield
ID: 41752908
double slash? Interesting...
0
 
LVL 41

Expert Comment

by:Sharath
ID: 41752963
Did it work? did you try?
0
 

Author Comment

by:Jerry Seinfield
ID: 41752968
It works, thanks, but now my user has denied access. That's another issue.
I appreciate your help.
0
 

Author Closing Comment

by:Jerry Seinfield
ID: 41752972
Thanks for your help
0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
PHP: Insert Data into MySQL 5 61
PHP & MySql - Turn Select Query Results into a Glyphicon 3 46
insert row field data graphically 4 32
Currency in SQL? 2 43
All XML, All the Time; More Fun MySQL Tidbits – Dynamically Generate XML via Stored Procedure in MySQL Extensible Markup Language (XML) and database systems, a marriage we are seeing more and more of.  So the topics of parsing and manipulating XM…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

713 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question