After experiencing a lot of down time, We decided to move this site to CrystalTech.com. CrystalTech.com is powered by only the finest Windows servers providing the best performance, reliability, and value anywhere.

 How to export a SQL View to CSV using VBScript

Author Message
VBNewbie07
  • Total Posts : 2
  • Scores: 0
  • Reward points : 0
  • Joined: 5/2/2007
How to export a SQL View to CSV using VBScript - Wednesday, May 02, 2007 7:50 AM
0
Hi all.
 
I would like to know if there is way to export a SQL View to a csv file using VBScript?
 
Thank you in advance!

dm_4ever
  • Total Posts : 3673
  • Scores: 82
  • Reward points : 0
  • Joined: 6/29/2006
  • Location: Orange County, California
RE: How to export a SQL View to CSV using VBScript - Wednesday, May 02, 2007 1:19 PM
0
Not certain, but you can export to a csv from an Access DB like this...

 Option Explicit
 
 Dim strDBPath : strDBPath = "c:\temp\test.mdb"
 Dim strCSVDirPath : strCSVDirPath = "c:\temp\"
 Dim strCSVFileName : strCSVFileName = "CSVExport.csv" 
 Dim strTableName : strTableName = "SomeTable" 
 Dim objConnection : Set objConnection = CreateObject("ADODB.Connection")
 objConnection.Open "Provider = Microsoft.Jet.OLEDB.4.0; " & _
                       "Data Source = " & strDBPath  
 Dim commandstring : commandstring = "SELECT * INTO [text;HDR=Yes;Database=" & _
                                     strCSVDirPath & "]." & strCSVFileName & _
                                     " FROM " & strTableName
 objConnection.Execute commandstring
 


You might be able to modify this to export from an SQL server...not sure though...  You might also just query the Table using ADO and use the GetString method to format the data and write it out to a .csv file.
dm_4ever

My philosophy: K.I.S.S - Keep It Simple Stupid
Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm

VBNewbie07
  • Total Posts : 2
  • Scores: 0
  • Reward points : 0
  • Joined: 5/2/2007
RE: How to export a SQL View to CSV using VBScript - Thursday, May 03, 2007 12:58 AM
0
Thanks dm_4ever!
 
I'll give it a try.

peachtea
  • Total Posts : 41
  • Scores: 0
  • Reward points : 0
  • Joined: 7/5/2007
  • Location: Singapore
RE: How to export a SQL View to CSV using VBScript - Tuesday, July 17, 2007 3:03 PM
0
hi there... just a qn to hijack this thread
 
is it possible for vb script to pick up certain information from 2 separate access tables and insert them into the 3rd table before export it out to a csv file?
All 3 tables r in the same db
 
Thanks in advance :)

dm_4ever
  • Total Posts : 3673
  • Scores: 82
  • Reward points : 0
  • Joined: 6/29/2006
  • Location: Orange County, California
RE: How to export a SQL View to CSV using VBScript - Tuesday, July 17, 2007 3:30 PM
0
I don't see why it wouldn't be possible with the right SQL query.
dm_4ever

My philosophy: K.I.S.S - Keep It Simple Stupid
Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm