Re: Newbie trying to put SQL Query into a VBScript

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Thanks SOOOO much, my script works great and I thank you for helping me
out!!

~B.


Richard Mueller wrote:
Assuming your connection string is good, rs is a recordset object, so it
cannot be echoed. You need to loop through the recordset, even if there is
only one row.
========
Do Until rs.EOF
objFile.Write rs.Fields("Tries").Value & ", " & rs.Fields("Doc").Value
rs.MoveNext
Loop
========
Or, if you are sure the is one and only one row, this should work:

ObjFile.Write rs.Fields("Tries").Value & ", " & rs.Fields("Doc").Value

I trust that your T-SQL statement is valid and returns one row.
--
Richard
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net

<gbpackerbacker@xxxxxxxxx> wrote in message
news:1161710170.012958.87340@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Sorry for not putting this in sooner. . .here is the code I'm trying to
make work. The error I get when I run it is: Error: Type Mismatch:
'Write'

Not sure what that is all about. . help is appriciated.

set cnn=createobject("ADODB.Connection")
cnn.open
("Provider=SQLOLEDB;server=SERVER;database=DB;uid=User;password=PWD")
set rs=cnn.execute("SELECT Retry AS Tries, COUNT(*) AS Docs FROM
dbo.DB_Batch GROUP BY Retry")
Set objFile = objFSO.OpenTextFile (("\\UNCPATH\Script_Results.txt"),
forAppending, createFile)
strWrite = rs
objFile.Write strWrite
objFile.Close
Wscript.Echo "Script is Finished with SQL Reporting. . . .moving onto
**NEXT**"


gbpackerbacker@xxxxxxxxx wrote:
I'm new to this whole scripting / sql game and I'm trying to automate
some reporting on a project of mine. Each day, I log into 5 differnt
servers and run a small program that returns any error counts. THis
data is stored in one central sql database and is much easier when I
run an SQL query on the database, rather than to have to log in to each
of the servers each morning.

Here's my problem, I have a script that I'm making to help automate
other processes that I do, and I want to add the SQL query into the
vbscript to automatically pull from the database, then write the
results of that query to a text file.

I do not know how to do this and would REALLY appriciate anyone's help
in this matter.

Thanks.


.



Relevant Pages

  • Re: Newbie trying to put SQL Query into a VBScript
    ... Assuming your connection string is good, rs is a recordset object, so it ... run an SQL query on the database, rather than to have to log in to each ... I have a script that I'm making to help automate ...
    (microsoft.public.scripting.vbscript)
  • Re: Newbie trying to put SQL Query into a VBScript
    ... servers and run a small program that returns any error counts. ... run an SQL query on the database, rather than to have to log in to each ... I have a script that I'm making to help automate ...
    (microsoft.public.scripting.vbscript)
  • Re: Help-news updater
    ... - first you need to create database 'msg_dbase' with sql query: ... CREATE DATABASE msg_dbase; ... subject char, text text, time timestamp); ... - then you need to create script that reads messages from database: ...
    (comp.lang.php)
  • Re: Help-news updater
    ... - first you need to create database with sql query: ... subject char, text text, time timestamp); ... then you need to create script that adds messages to database: ... then you need to create script that reads messages from database: ...
    (comp.lang.php)
  • Re: Help-news updater
    ... > I will that with form send data to database, and then that data read from ... > Name: Kole ... - first you need to create database with sql query: ... then you need to create script that reads messages from database: ...
    (comp.lang.php)