Re: Newbie trying to put SQL Query into a VBScript
- From: gbpackerbacker@xxxxxxxxx
- Date: 25 Oct 2006 06:39:24 -0700
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.
.
- References:
- Newbie trying to put SQL Query into a VBScript
- From: gbpackerbacker
- Re: Newbie trying to put SQL Query into a VBScript
- From: gbpackerbacker
- Re: Newbie trying to put SQL Query into a VBScript
- From: Richard Mueller
- Newbie trying to put SQL Query into a VBScript
- Prev by Date: Re: VBScript to Delphi: passing an opened stream object?
- Next by Date: How to create/store binary data as an Image file type?
- Previous by thread: Re: Newbie trying to put SQL Query into a VBScript
- Next by thread: msgbox and timeout
- Index(es):
Relevant Pages
|