I am trying to write a script that will execute SQL against each database in the system, then outputting the result sets to a text file. Here is what I have so far:
Code: Dim objFile Dim conn, rs1, rs2 Dim DBName, textfile, dbid
set rs2 = conn.Execute("Select * from"&DBName&"..SITE_DETAILS")
If rs2.EOF then WScript.Echo "No results"
Do Until rs2.EOF textfile.WriteLine(rs2) textfile.WriteLine("") loop
rs1.MoveNext loop
set rs1 = Nothing set rs2 = Nothing
textfile.Close conn.close set conn = Nothing
The result set rs1 is basically a list of all the databases I want to run the SQL against. So rs2 should basically run "Select * from Database1..SITE_DETAILS" then loop through again with Database2, Database3 etc. With each iteration I then want the results of rs2 to be printed to the textfile. I get 3 error messages with this script.
1. "A loop without a do statement" and it points to the loop for the Do Until rs1.EOF. When I comment out the second Do loop the error message goes away an the script runs if the inside loop is just a print statement. 2. That I cannot write rs2 to the text file as it is an object. 3. "DBName..SITE_DETAILS" is displayed as it should be in the error message, so shows "Database1..SITE_DETAILS" but then says the object is incorrect. But it is definitely correct.
I am assuming that the way I have gone about this is correct except for something relatively easy to fix, so if someone can point to the problem and direct me to a solution I would be extremely grateful!