×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

concatenate in SQL query

concatenate in SQL query

concatenate in SQL query

(OP)
Hello. I'm making a routine to run daily in SQL Workbench. I want the exported file to have curdate() added to the name for organizational purposes.

CODE --> SQL

SELECT
  d.emailaddress,
  d.fullname,
  d.address,
  d.city,
  d.state,
  d.zip,
  d.makepayabletoname,
  d.makepayabletoaddress,
  d.makepayabletocity,
  d.makepayabletostate,
  d.makepayabletozip,
  p.filenumber,
  p.paymentstatus,
  p.paymentamount,
  p.paymentdate
INTO OUTFILE '/tmp/' CURDATE();.'.csv'
FIELDS TERMINATED BY  ','
ENCLOSED BY '"'
ESCAPED BY '\\'
LINES TERMINATED BY '/\n'
FROM payments p
JOIN dbase d
ON p.filenumber = d.filenumber
WHERE p.paymentstatus = 'PENDING'
AND p.paymentdate = CURDATE(); 

The trouble line is: INTO OUTFILE '/tmp/' CURDATE();.'letters.csv' I want it to output to /tmp/2013-06-11letters.csv but I can't figure out how to concatenate.

[img="http://3dgstudios.com/images/gorilla.jpg"]

"Any sufficiently advanced technology is indistinguishable from magic" [Arthur C. Clark]</td></tr></table>

RE: concatenate in SQL query

(OP)
As an independent query, the following works fine. It does not work when i plug it into my query in the previous post.

CODE --> SQL

SELECT
  CONCAT('/tmp/',DATE_FORMAT(curdate(), '%Y-%m-%d'),'letters.csv') AS your_date; 

[img="http://3dgstudios.com/images/gorilla.jpg"]

"Any sufficiently advanced technology is indistinguishable from magic" [Arthur C. Clark]</td></tr></table>

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close