Friday, November 12, 2010

Pulling data from SQL via VB script

Hi,



To retrieve the data form data base :

1. In the remote machine à H:\ :Create a notepad and copy below code

2. 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)

3. Update the required server .(In the below code dev 90 is connected iiy replce 90 with 73,91,………….. as per requirement and environment ).

4. Then save it with “VBS” extension and double click the file .

5. 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

No comments:

Post a Comment