Here's a handy code snippit from the MySQL manual. Use it to convert an arbitrary SELECT statement into a .csv file:
SELECT * INTO OUTFILE 'c:/temp/dump.csv' FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY '\n' FROM <some-table> WHERE <some-where-clause>
I always forget how easy MySQL and PostgreSQL make it to get CSV data from a SELECT statement.
! Just solved a nightmare for me. Good work!
ReplyDeleteSo glad I could help!
ReplyDelete-Ben
hi.. when i tried to execute this, am getting error
ReplyDeleteMsg 102, Level 15, State 1, Line 1
Incorrect syntax near '\\Server\ServerShare\dump.csv'.
my query is
'Msg 102, Level 15, State 1, Line 1
Incorrect syntax near '\\Server\ServerShare\dump.csv'.'
help me :(
Anonymous said...
ReplyDeletehi.. when i tried to execute this, am getting error
Msg 102, Level 15, State 1, Line 1
Incorrect syntax near '\\Server\ServerShare\dump.csv'.
my query is
SELECT * INTO OUTFILE '\\Server\ServerShare\dump.csv'
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY '\n'
FROM tblConnection
help me :(
Hmmm...maybe you need to escape the slashes? So your path is:
ReplyDelete\\\\Server\\ServerShare\\dump.csv
Or maybe network shares aren't supported?
ya ya.. got it.. thanku so much !! its working fine now :)
ReplyDeleteSELECT * INTO OUTFILE '\\\\\Documents
ReplyDeleteand Settings\\user\\My Documents\\`mobile code`.txt'
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY '\n'
FROM `mobile code`
i execute this but incorrect error
This query is giving error
ReplyDelete