Wednesday, December 11, 2013

How to Pull the data from SQL via VB script

to pull the data from Sql via VB Script we need to follow these steps:

  •  In the remote machine à H:\ :Create a notepad and copy below code 
  •  Update the required SQL query in the below string “Sqlquery” and query should retrieve only one value .(while editing the query selectà Editàx.vbs)
  •  Update the required server .(In the below code dev 90 is connected iiy replce 90 with 73,91,………….. as per requirement and environment ).
  •  Then save it with “VBS” extension and double click the file .
  • Verify the result in the H:\SQLResult.txt
strConn = "DRIVER={SQL Server};SERVER=sqlvirdev0090\dev90,6090;Database=rr_ge_db01;"

Set con = CreateObject("adodb.connection")

con.Open strConn

Sqlquery = "(select rx_i from rx where asgn_rx_i='80087139')"

Set Value = con.Execute(Sqlquery)

dbvalue = Value.fields(0)

'MsgBox dbvalue

Set txt = CreateObject("scripting.filesystemobject")

Set txt1 = txt.createtextfile("H:\ SQLResult.txt", True)

txt1.writeline dbvalue