Export query result to csv file 
April 23rd, 2009, 03:16 AM
|  | Member | | Join Date: May 2007
Posts: 61
| | |
i wanted to export the query result into csv file
is there any way to do it.,
e.g. select field1,field2 from table into csvfile
| 
April 23rd, 2009, 04:18 AM
|  | Expert | | Join Date: Jan 2008 Location: Sydney
Posts: 769
Provided Answers: 5 | | | re: Export query result to csv file
You could link an excel worksheet as a table and run an insert query into the linked worksheet.
| 
April 23rd, 2009, 04:35 AM
|  | Member | | Join Date: May 2007
Posts: 61
| | | re: Export query result to csv file
how about in sql query., is there a way to do it in pure sql statement
| 
April 23rd, 2009, 04:56 AM
|  | Expert | | Join Date: Jan 2008 Location: Sydney
Posts: 769
Provided Answers: 5 | | | re: Export query result to csv file
Not that I am aware of.
You coud do it with a combination of VBA, (DAO or ADO) and VBA file handling functionality.
Open a text file object
Open A recordset object from your query
loop through each record
add each fields content separated with commas to the file
close the recordset object
close the file object
You could also do a similar thing with vbscript and the File system object.
Again using ADO to query the DB
The advantage there would be you could schedule the script to run automatically.
If that was important.
| 
April 23rd, 2009, 05:13 AM
|  | Expert | | Join Date: Jan 2008 Location: Sydney
Posts: 769
Provided Answers: 5 | | | re: Export query result to csv file
well, time to take foot out of mouth :)
1) Create your csv file
2) Add 1 row of comma separated data.
3) Link the csv file as a table. (there must be at least 1 row of data or it wont link)
4) Create your query and make it an append query (into the linked csv)
5) Run the query
6) Close Database
7) Open csv file and VOILA
| 
April 23rd, 2009, 01:39 PM
|  | Administrator | | Join Date: Oct 2006 Location: London - UK
Posts: 15,450
Provided Answers: 56 | | | re: Export query result to csv file
An alternative would be to create a simple SELECT QueryDef, and Export (File / Export...) this into your new CSV file.
|  | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 225,652 network members.
|