Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using SELECT/WHERE and save the resultset into a text file 2

Status
Not open for further replies.

zyrag

IS-IT--Management
Dec 4, 2002
252
PH
hi, i want to save the data entered during the day. this i would want to happen every last office hour of the day, say every 5:00p.

SELECT * from tbl_names WHERE DATE=today

but, how am i going to save the result into a text file?

hope you can share your valuable ideas to a newbie like me...

thanks in advance



 
common csv format :

SELECT * into outfile '/path/to/file/filename.csv' fields enclosed by '"' terminated by ',' lines terminated by '\n' FROM yourtable WHERE date = curdate(); ______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
thank you very much Karver. is it also possible to output from one or more table into 1 single csv file using the expression? say,

SELECT tbl1.col1, tbl2.col1, tbl2.col2 into outfile '/path/to/file/filename.csv' fields enclosed by '"' terminated by ',' lines terminated by '\n' FROM tbl1, tbl2, WHERE tbl1.col1=tbl2.col1 AND transdate = curdate();

thanks again...
 
Yes, what you have above should work just fine. ______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
karver thanks a lot...

i tried to execute the command:

SELECT * INTO OUTFILE 'C:\\mysamp.txt'
FIELDS enclosed by '\"' terminated by ','
LINES terminated by '\n\r'
FROM USER;

The output seemed OK except that the newline and carriage return character doesn't seem to work. The output should have 5 rows but instead it contained only 1 text line.

why? what should be the right way to do it?

thanks again...
 
Normally I just use \n , never had any probs under linux, sco or windoze ;-) ______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
got it right now... thanks to you guys.
 
Does it need any special privilege to do this operation? I tried it on a remote Mysql server but it didn't work. why?
 
FILE privileges must be set for MySQL > 3.22 on th esever config (or possibly just the target directory be world writeable) on the server. Cant remember exactly, so dee FILE in the manual.

______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top