SQL Query via WSH 
Author Message
 SQL Query via WSH

Hi,

Has anyone used WSH to query a SQL Server or ODBC data source, with the
output as a text file?

Best Regards

Trevor Dwyer



Sat, 07 Apr 2001 03:00:00 GMT  
 SQL Query via WSH

To run this sample create the c:\pubs.txt file and the pubs system DSN (assuming you have a SQL Server, pubs is the sample db installed with SQL)

Set FSO = CreateObject("Scripting.FileSystemObject")
Set AFileStream = FSO.OpenTextFile("c:\pubs.txt",2)
 Dim conn, rs,SQLText, AuthorList
 Set conn=CreateObject("ADODB.Connection")
 Set rs=CreateObject("ADODB.Recordset")
 SQLText = "Select * From Authors"

 Conn.ConnectionString="DSN=PUBS"
 Conn.Open
 rs.Open SQLText, Conn, 0,1
 If rs.EOF Then
  msgBox "No Records Found"
  rs.Close
  Conn.Close
  Exit Sub
 End If
 Do Until rs.EOF
  AFileStream.WriteLine rs("au_fname") & " " & rs("au_lname")
  rs.MoveNext
 Loop
 AFileStream.close
 rs.Close
 Set rs=Nothing
 Conn.Close
 Set Conn=Nothing

This code is in the WSH FAQ
regards,
Ian


    Hi,

    Has anyone used WSH to query a SQL Server or ODBC data source, with the
    output as a text file?

    Best Regards

    Trevor Dwyer



Sun, 08 Apr 2001 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Query an access database via SQL in VB6

2. Access 97 running SQL Query and Macro from WSH in VBScript

3. Query BIOS via WSH

4. Querying AD user properties via ADSI (WSH)

5. VBScript- SQL Query of MS SQL 7 Database

6. Sql query error

7. SQL Query HELP

8. Need help with some ASP SQL query...

9. SQL Query question

10. SQL queries, ASP and VBScript

11. SQL Query for null not returning any data

12. Did SQL + ODBC Query Succeed?

 

 
Powered by phpBB® Forum Software