Connecting Tech Pros Worldwide Help | Site Map

Export query result to csv file

  #1  
Old April 23rd, 2009, 03:16 AM
xxoulmate's Avatar
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
  #2  
Old April 23rd, 2009, 04:18 AM
Delerna's Avatar
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.
  #3  
Old April 23rd, 2009, 04:35 AM
xxoulmate's Avatar
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
  #4  
Old April 23rd, 2009, 04:56 AM
Delerna's Avatar
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.
  #5  
Old April 23rd, 2009, 05:13 AM
Delerna's Avatar
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
  #6  
Old April 23rd, 2009, 01:39 PM
NeoPa's Avatar
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.
Reply


Similar Threads
Thread Thread Starter Forum Replies Last Post
Export to a CSV file ramdil answers 5 February 22nd, 2008 02:28 PM
export arabic data to csv format farukcse answers 1 December 23rd, 2007 07:39 PM
data transfer from .csv file to sql server 2000 sachin shah answers 2 August 16th, 2007 10:25 AM
Export Table to .csv (tab delimited) FallingReign answers 4 March 10th, 2007 12:51 AM