By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,657 Members | 1,760 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,657 IT Pros & Developers. It's quick & easy.

Export query result to csv file

xxoulmate
P: 77
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
Apr 23 '09 #1
Share this Question
Share on Google+
5 Replies


Delerna
Expert 100+
P: 1,134
You could link an excel worksheet as a table and run an insert query into the linked worksheet.
Apr 23 '09 #2

xxoulmate
P: 77
how about in sql query., is there a way to do it in pure sql statement
Apr 23 '09 #3

Delerna
Expert 100+
P: 1,134
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.
Apr 23 '09 #4

Delerna
Expert 100+
P: 1,134
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
Apr 23 '09 #5

NeoPa
Expert Mod 15k+
P: 31,712
An alternative would be to create a simple SELECT QueryDef, and Export (File / Export...) this into your new CSV file.
Apr 23 '09 #6

Post your reply

Sign in to post your reply or Sign up for a free account.