Solved

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

Posted on 2016-08-11
5
46 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 40

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 40

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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Join & Write a Comment

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

744 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now