VBS Get Sql Server Table Data and Export to CSV File...

 

  '----------------------------------------------------
  'Author: Lilo.Zhu
  'Creation Date: 2010-05-26
  'Description: Get MES Hyperion and Export to CSV File
  '-----------------------------------------------------          
Dim Input
Input = InputBox("Enter your Export File Name:" & vbCrLf & vbCrLf &  "Eg:" & vbCrLf & vbCrLf &"//dg2pcXXX/ShareFolder/")
If Input <>"" then
 set conn = CreateObject("ADODB.Connection")
     conn.open _
      "Provider=SQLOLEDB;Data Source=dr_mesdb;" & _
         "Trusted_Connection=Yes;Initial Catalog=InsiteProdDG;" & _
              "User ID=sqlreport;Password=sqllqs;"
     
 set rs = conn.execute("SELECT * FROM WIPDOLLAR_Hyperion_view")
 csvText = rs.getString(2,,",",VBCrLf)
 rs.close: set rs = nothing
 conn.close: set conn = nothing
 
  Dim l_sn
  l_sn=Replace(Now,"-","")
  l_sn=Replace(l_sn,":","")
  l_sn=Replace(l_sn," ","")
 
 set fso = CreateObject("Scripting.FileSystemObject")
 set fs = fso.CreateTextFile(Input& l_sn &".csv", true)
 fs.writeline(csvText)
 fs.close: set fs = nothing
 set fso = nothing
End if

 

posted on 2010-05-26 15:08  封起De日子  阅读(113)  评论(0编辑  收藏  举报

导航