mbt masai
 
Welcome !
         

                                
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
  • Status: offline
How to export a SQL View to CSV using VBScript Wednesday, May 02, 2007 7:50 AM (permalink)
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!
#1
    dm_4ever

    • Total Posts : 3673
    • Scores: 82
    • Reward points : 0
    • Joined: 6/29/2006
    • Location: Orange County, California
    • Status: offline
    RE: How to export a SQL View to CSV using VBScript Wednesday, May 02, 2007 1:19 PM (permalink)
    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
    #2
      VBNewbie07

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

        • Total Posts : 41
        • Scores: 0
        • Reward points : 0
        • Joined: 7/5/2007
        • Location: Singapore
        • Status: offline
        RE: How to export a SQL View to CSV using VBScript Tuesday, July 17, 2007 3:03 PM (permalink)
        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 :)
        #4
          dm_4ever

          • Total Posts : 3673
          • Scores: 82
          • Reward points : 0
          • Joined: 6/29/2006
          • Location: Orange County, California
          • Status: offline
          RE: How to export a SQL View to CSV using VBScript Tuesday, July 17, 2007 3:30 PM (permalink)
          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
          #5

            Online Bookmarks Sharing: Share/Bookmark

            Jump to:

            Current active users

            There are 0 members and 1 guests.

            Icon Legend and Permission

            • New Messages
            • No New Messages
            • Hot Topic w/ New Messages
            • Hot Topic w/o New Messages
            • Locked w/ New Messages
            • Locked w/o New Messages
            • Read Message
            • Post New Thread
            • Reply to message
            • Post New Poll
            • Submit Vote
            • Post reward post
            • Delete my own posts
            • Delete my own threads
            • Rate post

            2000-2012 ASPPlayground.NET Forum Version 3.8
            mbt shoes www.wileywilson.com